Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serverless Error: The header content contains invalid characters #3202

Closed
j-lowry opened this issue Feb 7, 2017 · 20 comments
Closed

Serverless Error: The header content contains invalid characters #3202

j-lowry opened this issue Feb 7, 2017 · 20 comments

Comments

@j-lowry
Copy link

j-lowry commented Feb 7, 2017

This is a Bug Report

Description

On running a test deployment received the error message

 Error --------------------------------------------------
 
     ServerlessError: ServerlessError: The header content
     contains invalid characters

The expected behavior was either a successful deployment or at least an error message from AWS about the relating to the configuration.

  • What was the config you used?
  • What stacktrace or error message from your provider did you see?

Additional Data

  • Serverless Framework Version you're using: 1.6.1
  • Operating System: darwin
  • Stack Trace:
Error: ServerlessError: ServerlessError: The header content contains invalid characters
    at module.exports.logError (/usr/local/lib/node_modules/serverless/lib/classes/Error.js:87:11)
    at BbPromise.resolve.then.catch.e (/usr/local/lib/node_modules/serverless/bin/serverless:26:3)
    at runCallback (timers.js:651:20)
    at tryOnImmediate (timers.js:624:5)
    at processImmediate [as _immediateCallback] (timers.js:596:5)
From previous event:
    at __dirname (/usr/local/lib/node_modules/serverless/bin/serverless:24:9)
    at Object.<anonymous> (/usr/local/lib/node_modules/serverless/bin/serverless:27:4)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:418:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:533:3
  • Provider Error messages:
ServerlessError: ServerlessError: The header content
     contains invalid characters
@pmuens
Copy link
Contributor

pmuens commented Feb 7, 2017

Hey @j-lowry thanks for opening.

Could you please share your serverless.yml and the corresponding handler file? Thanks!

@j-lowry
Copy link
Author

j-lowry commented Feb 7, 2017

handler.py:

$ cat handler.py 
import json

def hello(event, context):
    body = {
        "message": "Go Serverless v1.0! Your function executed successfully!",
        "input": event
    }

    response = {
        "statusCode": 200,
        "body": json.dumps(body)
    }

    return response

    # Use this code if you don't use the http event with the LAMBDA-PROXY integration
    """
    return {
        "message": "Go Serverless v1.0! Your function executed successfully!",
        "event": event
    }
    """

@j-lowry
Copy link
Author

j-lowry commented Feb 7, 2017

serverless.yml:

$ cat handler.py 
import json

def hello(event, context):
    body = {
        "message": "Go Serverless v1.0! Your function executed successfully!",
        "input": event
    }

    response = {
        "statusCode": 200,
        "body": json.dumps(body)
    }

    return response

    # Use this code if you don't use the http event with the LAMBDA-PROXY integration
    """
    return {
        "message": "Go Serverless v1.0! Your function executed successfully!",
        "event": event
    }
    """

@pmuens
Copy link
Contributor

pmuens commented Feb 7, 2017

@j-lowry thanks for the response.

Unfortunately the serverless.yml is missing. Could you update the corresponding comment? Thanks!

@j-lowry
Copy link
Author

j-lowry commented Feb 7, 2017

Woops, sorry about that. Below is the serverless.yml:

$ cat serverless.yml 
# Welcome to Serverless!
#
# This file is the main config file for your service.
# It's very minimal at this point and uses default values.
# You can always add more config options for more control.
# We've included some commented out config examples here.
# Just uncomment any of them to get that config option.
#
# For full config options, check the docs:
#    docs.serverless.com
#
# Happy Coding!

service: test-python

# You can pin your service to only deploy with a specific Serverless version
# Check out our docs for more details
# frameworkVersion: "=X.X.X"

provider:
  name: aws
  runtime: python2.7

# you can overwrite defaults here
#  stage: dev
#  region: us-east-1

# you can add statements to the Lambda function's IAM Role here
#  iamRoleStatements:
#    - Effect: "Allow"
#      Action:
#        - "s3:ListBucket"
#      Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ]  }
#    - Effect: "Allow"
#      Action:
#        - "s3:PutObject"
#      Resource:
#        Fn::Join:
#          - ""
#          - - "arn:aws:s3:::"
#            - "Ref" : "ServerlessDeploymentBucket"

# you can define service wide environment variables here
#  environment:
#    variable1: value1

# you can add packaging information here
#package:
#  include:
#    - include-me.py
#    - include-me-dir/**
#  exclude:
#    - exclude-me.py
#    - exclude-me-dir/**

functions:
  hello:
    handler: handler.hello

#    The following are a few example events you can configure
#    NOTE: Please make sure to change your handler code to work with those events
#    Check the event documentation for details
#    events:
#      - http:
#          path: users/create
#          method: get
#      - s3: ${env:BUCKET}
#      - schedule: rate(10 minutes)
#      - sns: greeter-topic
#      - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000
#      - alexaSkill
#      - iot:
#          sql: "SELECT * FROM 'some_topic'"

#    Define function environment variables here
#    environment:
#      variable2: value2

# you can add CloudFormation resource templates here
#resources:
#  Resources:
#    NewResource:
#      Type: AWS::S3::Bucket
#      Properties:
#        BucketName: my-new-bucket
#  Outputs:
#     NewOutput:
#       Description: "Description for the output"
#       Value: "Some output value"

@pmuens
Copy link
Contributor

pmuens commented Feb 8, 2017

Hmm. That's odd 🤔

So in essence you've done the following:

serverless create --template aws-python --path test-python

cd test-python

serverless deploy

And after that you saw the error? I tried to reproduce it locally but was not successfull...

@j-lowry
Copy link
Author

j-lowry commented Feb 8, 2017

Yes, that is what I saw. I just recreated it again. I am going to go through my local workstation. I running npm from homebrew, not sure if there is some issue there.

@andymac4182
Copy link
Contributor

I have seen this before in another system with the file being encoded with UTF-8 with BOM. Not sure how it happens. I can see that as an encoding in VSCode in the bottom right hand corner.

@pmuens
Copy link
Contributor

pmuens commented Feb 9, 2017

@andymac4182 thanks for the pointer. Good idea to check that!

@j-lowry so do you still get the same error if you remove the old service and create a new one from scratch and then deploy that?

@j-lowry
Copy link
Author

j-lowry commented Feb 9, 2017

Unfortunately yes.

@pmuens
Copy link
Contributor

pmuens commented Feb 13, 2017

Hey @j-lowry

There seems to be nothing wrong with your serverless.yml and handler file.

I found this comment about credentials setup for the aws-sdk: request/request#2120 (comment)

Maybe it has something todo how your credentials are setup on your local machine...

@j-lowry
Copy link
Author

j-lowry commented Feb 13, 2017

Over the weekend I got it working on a linux host with the same credentials. I nuked my $HOME/.aws/ directory to test with just environment variables and still getting the same error message. I wonder if I have a "/" in the secret_access_key and it is throwing everything off.

@j-lowry
Copy link
Author

j-lowry commented Feb 13, 2017

Yeah, I just regenerated a secret access key without a "/" in it and it works now.

@pmuens
Copy link
Contributor

pmuens commented Feb 14, 2017

Thanks for reproducing @j-lowry 👍 That's really interesting!

Adding the bug label here... Not sure if we fix it soon (or if it's something on AWS to look into as well) as it's a kind of edge case.

@pmuens
Copy link
Contributor

pmuens commented Mar 9, 2017

Closing this for now since it's an edge case and might be something AWS should fix...

@pmuens pmuens closed this as completed Mar 9, 2017
@waqasiftikhar2
Copy link

Hi, I am facing the very same error. But I don't have "/" in my access key or secret key either.

I have also done the same:
serverless create --template aws-python --path test-python
cd test-python
serverless deploy

Serverless Error ---------------------------------------

ServerlessError: The header content contains invalid characters

Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Forums: forum.serverless.com
Chat: gitter.im/serverless/serverless

Your Environment Information -----------------------------
OS: darwin
Node Version: 8.4.0
Serverless Version: 1.23.0

@waqasiftikhar2
Copy link

Well, it seems the problem occurs if you have some sort of special characters in you access key secret. I had a "+" in it. I was able to successfully generate another one without any special characters i.e. all alphabets and it worked then.

@rahuljain840
Copy link

@waqasiftikhar2 are you sure about it? because I too have + in my secret access and I am getting the same error.

@alexjurkiewicz
Copy link

I am running into this error as well. I see the error when running AWS_PROFILE=foo yarn run sls deploy, but not with AWS_ACCESS_KEY_ID=x AWS_SECRET_ACCESS_KEY=x AWS_DEFAULT_REGION=x AWS_REGION=x yarn run sls deploy.
My ~/.aws/credentials file contains nothing out of the ordinary.

If it matters, I'm running this sls command from a Python (2.7) script.

@mrjgallagher
Copy link

Hello,

I ran into this error also.
My ~/.aws/credentials, [or C:\Users\james.aws\credentials on Win10] had a special character and also a new line in it.

Removing both fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants