AWS Lambda

Discover the potential of the Lambda function in serverless architectures.

AWS Lambda is a serverless compute service that allows us to run code without provisioning or managing servers. It falls under the Function-as-a-Service (FaaS) service model, where the user provides the code, and the underlying infrastructure is managed by the cloud.

Press + to interact

In a serverless architecture, the Lambda function adds business logic and acts as a glue between multiple managed services, charging the user for the execution time.

How Lambda functions work

Each lambda function consists of three essential components:

  • Invocation event: It comprises data, typically in the form of a JSON packet, and its contents vary depending on the service. For instance, API Gateway events provide details such as path, HTTP method, query string parameters, headers, cookies, and more. DynamoDB events may include data related to updated or deleted records, while S3 events contain information like the bucket name and object key.

  • Function handler: A method within your function code processes the incoming event. This handler, a standard function in your chosen programming language, executes tasks and produces a resulting event. The code snippet below shows the default function handler in Python.

Press + to interact
def lambda_handler(event, context):
# Your function logic goes here
return {
'statusCode': 200,
'body': 'Hello from Lambda!'
}

This function receives two arguments: event and context and returns a JSON body with a 200 status code and a message.

  • ...