Categories
AWS

AWS: SAM gotchas

If your lambda is just returning before expected, check the default Timeout in template.yaml, most likely you will need a bigger number there

Commands:

sam build

(pack the latest changes, it will rerun anything new you put in requirements.txt as well

sam local invoke “YourFunctionName” -e events/yourevent.json

run your function locally, with your own event

sam deploy

put it out there

Categories
AWS

AWS lambda: the basics

For a API Gate / Lambda combo, there is a bit of a gotch when setting those two services together and following their hello world example.

Instead of the default in their example:

# print(“value2 = ” + event[‘key2’])

use:

event[‘params’][‘querystring’][‘key1’]

I wish it was more evident in their documentation what “event” means, but basically, after you set the above, you need to also set the query params (spell out what they will be) under: Amazon API Gateway / Resources / Method execution

Also, in that section, Integration Request, specify:

When there are no templates defined (recommended)”

and add a new template for: “application/json”

In the “Generate Template” section, choose: “Method Request Pass through”

Leave the default code in there, and now, when you pass your parameters as:

your-api-gateway-url?yourparam=yourvalue

you will see those values in your python script as:

event[‘params’][‘querystring’][‘yourparam’]