0

I'm really new to API dev and don't have a broad background knowledge. So please bear that in mind if my question looks too simple (stupid). I was playing around with serverless and the AWS lambda to get a better understanding of API's. It was pretty easy to define a simple function and define a http endpoint for a get request. However, with a post event I have my troubles.

As far as I understood and according to the documentation a typical lambda function is always of the template:

def my_function(event, context):
    pass

If I understand it correctly, the event parameter contains the actual input parameters sent to my function. If my API would take a string as input and just capitalize it, the input string would be part of the event object. Is this correct?

Are there any rules how the event object needs to look like, how I can pass parameters to it etc? I wasn't really able to find that information. If someone could provide this information or a link where I can find the resources would be much appreciated.

2 Answers 2

3

You are correct that event is the variable receiving the input (aka payload). In most cases this should be a json-friendly dict, but it can also be list, str, int, float, or NoneType.

When you invoke your Lambda, for example from another Python application using boto3, you simply pass this payload.

If you need to provide an HTTP interface for your Lambda, the best option is probably to use API Gateway with Lambda Proxy Integration. In this case you can POST json and the API Gateway will automatically parse it to Python dict and provide to you in the event. Please note that in this case your return from the Lambda should follow some basic requirements.

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

Comments

2

Try configuring test events in Lambda console.

It will give a variety of sample event structures which will help you

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.