4

Normally, for testing lambda locally, I use

sam local invoke WebhookFunction -e test.json

in test.json

{"body":"test"}

This valiable is passed to event.

def lambda_handler(event, context):

Now I want to do equivalent thing by curl

I tried this.

curl -X POST -H "Content-Type: application/json" -d '{"body":"test"}'

however I think {"body":"test"} is not correctly passed to event.

I guess I need to set something more.

Can anyone help me?

1 Answer 1

3

This won't work, unless you have a lambda RIE (Runtime Interface Emulator) running as a proxy for the Lambda Runtime API locally.

Depending on the language you've written your lambda in, you need to build a docker image and run it locally.

Finally, you can do this:

$ curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}'

This command invokes the Lambda function running in the container image and returns a response.


You can use one of the AWS base images for Lambda to build the container image for your function code.

Choose your lambda language and follow the instructions here.

Finally, test your lambda container locally with RIE.

There's a really nice blog post that walks you through the entire process here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.