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
Top comments (0)