Creating lambdas in localstack

Issue #49 resolved
rsrestha created an issue

Hi, I was trying to run a lambda on localstack.

But when I enter the following command:

aws --endpoint-url=http://localhost:4574 lambda create-function --function-name=f1 --runtime=python2.7 --role=r1 --handler=lambda.handler --zip-file fileb://lambda.zip

*(For uploading the lambda) *

It prompts the following: Unable to locate credentials. You can configure credentials by running "aws configure".

Comments (8)

  1. Marco Lüthy

    (I'm not associated with Localstack)

    @rsrestha have you tried providing the AWS CLI with some dummy environment configuration? For example, try this:

    export AWS_ACCESS_KEY_ID=foobar
    export AWS_SECRET_ACCESS_KEY=foobar
    export AWS_DEFAULT_REGION=us-east-1
    
    aws --endpoint-url=http://localhost:4574 lambda create-function --function-name=f1 --runtime=python2.7 --role=r1 --handler=lambda.handler --zip-file fileb://lambda.zip
    
  2. Waldemar Hummer Account Deactivated

    Thanks for reporting @rsrestha . This error message is related to the way the AWS command-line interface (CLI) is configured. The CLI requires the user to specify an Access Key and a Secret Key. Even though LocalStack is not making use of these keys, you have to specify them regardless (in fact you can specify an arbitrary string like "foobar" for the keys and it will still work.)

    You basically have two options:

    1. Running aws configure and provide the required data. This will write the configuration values to $HOME/.aws/config.
    2. Specify the following environment variables:
    export AWS_ACCESS_KEY_ID=foobar
    export AWS_SECRET_ACCESS_KEY=foobar
    export AWS_DEFAULT_REGION=us-east-1
    

    Can you please give that a try and confirm that it works for you? Thanks

  3. Waldemar Hummer Account Deactivated

    Oh, thanks @adieuadieu , didn't notice that you had already answered the question!

  4. rsrestha reporter

    Hello,

    Thanks for the quick response, and apologies for my delay.

    Unfortunately, i'm still not able to run the lambdas. I did, however, follow the above listed steps, and the lambda is getting uploaded as it should,

    BUT,

    On executing the command for running: aws lambda --endpoint-url=http://localhost:4574 invoke --function-name f1 result.log

    This is what i'm getting as output: An error occurred (UnsupportedMediaTypeException) when calling the Invoke operation: The payload is not JSON

    Contents of my lambda.py:

    def handler(event,context):
        print('test')
        return {'foo':'bar'}
    

    also, i'm afraid i can't find the log file where the result is said to be stored.

  5. Marco Lüthy

    @rsrestha you might need to specify the --payload flag on the CLI command:

    aws lambda --endpoint-url=http://localhost:4574 invoke --function-name f1 --payload "{}" result.log
    
  6. Waldemar Hummer Account Deactivated

    Thanks for the follow up @rsrestha . The new error message is a legitimate bug, we'll look into it shortly.

    As a workaround for now, you can specify the payload as mentioned by Marco.

  7. Log in to comment