TIL: Create and deploy a serverless function in AWS
Only two steps required (it assumes an existing account in AWS console):
- Create a Lambda function in AWS
- Deploy your Lambda function with AWS API Gateway
I used these two articles as a reference:
- Going Serverless: how to run your first AWS Lambda function in the cloud
- Working with Amazon API Gateway
Important notes
the lambda function (also called lambda_handler), has two parameters: event and context. When calling this function, most of the time you are only passing the arguments as the event, even if you are using more than one argument. For example, a function that multiplies two numbers, would look like this:
def multiply(event, context):
num_1 = event['number_1']
num_2 = event['number_2']
return num_1 * num_2
when this function is deployed with AWS API Gateway, you receive a URL, like an endpoint to call, so these two arguments are added to the URL as in:
https://generated-aws-link?number_1=3&number_2=5
Side note reminder: consider input sanitization to increase web app security
The post _TIL: Create and deploy a serverless function in AWS_was originally published at flaviabastos.ca