Creating lambdas in localstack
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)
-
-
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:
- Running
aws configure
and provide the required data. This will write the configuration values to$HOME/.aws/config
. - 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
- Running
-
Account Deactivated Oh, thanks @adieuadieu , didn't notice that you had already answered the question!
-
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.
-
@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
-
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.
-
Account Deactivated This is fixed in commit 39adfeb15c23c3b37907de7393d87a5dfaef1a60 . The Docker image is currently being built and pushed: https://bitbucket.org/atlassian/localstack/addon/pipelines/home#!/results/%7Be386fc56-6cc3-4a16-9518-0fdb69e1e7f3%7D
Once the build is finished, can you please try pulling the latest image (tags
0.6.0
andlatest
). Closing this issue now, please feel free to re-open if the problem persists. Thanks. -
Account Deactivated - changed status to resolved
- Log in to comment
(I'm not associated with Localstack)
@rsrestha have you tried providing the AWS CLI with some dummy environment configuration? For example, try this: