AWS Lambda — Serverless Functions Guide

Sanjeev SharmaSanjeev Sharma
1 min read

Advertisement

AWS Lambda — Serverless Functions Guide

AWS Lambda enables serverless computing without managing servers or infrastructure.

Creating Functions

# handler.py
def lambda_handler(event, context):
    return {
        'statusCode': 200,
        'body': 'Hello from Lambda!'
    }
# Deploy
zip function.zip handler.py
aws lambda create-function \
  --function-name my-function \
  --runtime python3.11 \
  --role arn:aws:iam::ACCOUNT:role/lambda-role \
  --handler handler.lambda_handler \
  --zip-file fileb://function.zip

Triggers

# API Gateway trigger
aws lambda create-function-url-config \
  --function-name my-function \
  --auth-type NONE

# S3 trigger
aws s3api put-bucket-notification-configuration \
  --bucket my-bucket \
  --notification-configuration file://notification.json

FAQ

Q: What's the cold start penalty? A: First invocation takes longer (1-2 seconds). Subsequent invocations faster.

Q: Can I use containers in Lambda? A: Yes, with container images up to 10GB.

Advertisement

Sanjeev Sharma

Written by

Sanjeev Sharma

Full Stack Engineer · E-mopro