Your First AWS Lambda Function in 20 Minutes
Lambda is the simplest cloud compute. The 20 minutes get you from zero to a callable function.
Step 1: Write the function
def handler(event, context):
return {"statusCode": 200, "body": "hello"}
Save as app.py.
Step 2: Deploy via SAM
- Install SAM CLI; create a SAM template.yaml referencing app.py.
sam build && sam deploy --guided, deploys the function + API Gateway.
Step 3: Invoke
curl https://<your-api-url>, should return ‘hello.’
Function executed; logs in CloudWatch.
Step 4: Logs and monitoring
CloudWatch Logs: every invocation logged.
CloudWatch Metrics: invocation count, duration, errors.
Add custom metrics with boto3.
Antipatterns
- Lambda without timeout config. Default 3s; many use cases need more.
- Hard-coding secrets. Use Secrets Manager.
- Default memory size. Tune for your workload.
What to do this week
Three moves. (1) Run the tutorial end-to-end on your own laptop / sandbox. (2) Apply the pattern to one production workload. (3) Document the variations you needed; share with the team.