DEV Community

Flávia Bastos
Flávia Bastos

Posted on • Originally published at flaviabastos.ca on

3

TIL: Create and deploy a serverless function in AWS

Only two steps required (it assumes an existing account in AWS console):

  1. Create a Lambda function in AWS
  2. Deploy your Lambda function with AWS API Gateway

I used these two articles as a reference:

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

Do your career a big favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Community matters

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay