# AWS Lambda Functions

> Write, deploy and tune Lambda functions: handlers, triggers, execution roles, memory and timeouts, cold starts, layers and concurrency. Free notes, key...

Canonical: https://www.internhack.in/roadmaps/tracks/cloud-engineer/lambda
Last updated: 2026-11-28

Write, deploy and tune Lambda functions: handlers, triggers, execution roles, memory and timeouts, cold starts, layers and concurrency.

Intermediate · about 6 hours · difficulty 3/5

Learn first: [STS, Assume Role and Federation](https://www.internhack.in/roadmaps/tracks/cloud-engineer/iam-roles-federation), [Amazon S3 Fundamentals](https://www.internhack.in/roadmaps/tracks/cloud-engineer/s3-fundamentals)

**AWS Lambda** runs your code in response to events without servers to manage. You pay per request and per millisecond of compute, and the free tier covers a generous number of invocations every month. Azure Functions and Google Cloud Functions / Cloud Run functions are the equivalents.

### The basics

- A **handler** function receives an **event** (an HTTP request, an S3 upload, a queue message) and a **context**.
- Runtimes include Node.js, Python, Java, Go (via the OS-only runtime), .NET, or any language as a **container image**.
- Each function has an **execution role** that decides what AWS APIs it can call.
- Configure **memory** (128 MB to 10 GB); CPU scales with it. **Timeout** is up to 15 minutes.

### Triggers

- Synchronous: API Gateway, function URLs, ALB.
- Asynchronous: S3, SNS, EventBridge (with retries and **destinations** or dead-letter queues).
- Poll-based: SQS, DynamoDB Streams, Kinesis (event source mappings with batching).

### Performance and scaling

- **Cold starts** happen when a new execution environment is created. Keep packages small, initialize clients outside the handler, and use **SnapStart** or **provisioned concurrency** when latency matters.
- **Concurrency** limits protect downstream databases. Use **reserved concurrency** to cap a function.
- Use **Powertools for AWS Lambda** for structured logging, tracing and idempotency.

### Pitfalls

- Using Lambda for long-running or always-busy workloads where containers are cheaper.
- Opening a new database connection on every invocation; use RDS Proxy or DynamoDB.
- Non-idempotent handlers that double-charge when an event is retried.

You are ready to move on when you can deploy a function triggered by an S3 upload that writes metadata to DynamoDB, and explain cold starts and retries.

## Key concepts

- **Handlers, events and context**
- **Execution roles**
- **Memory, CPU and timeouts**
- **Sync, async and poll-based triggers**
- **Cold starts**
- **Concurrency and throttling**
- **Layers and container images**
- **Idempotency**
- **Powertools for AWS Lambda**

## Mini project

Build an image thumbnail pipeline: uploading a JPG to an S3 bucket triggers a Lambda that writes a resized copy to a second bucket and records metadata in DynamoDB. Use small test images so everything stays within the always-free Lambda and DynamoDB limits, and delete buckets, table and function afterwards.

## Check yourself

Your Lambda writes to S3 and is triggered by uploads to the same bucket. What goes wrong, and how do you prevent it?

## Free resources

- [AWS Lambda documentation](https://docs.aws.amazon.com/lambda/) (AWS)
- [Serverless Land](https://serverlessland.com/) (AWS)
- [Powertools for AWS Lambda (Python)](https://docs.powertools.aws.dev/lambda/python/latest/) (AWS)

Previous: [Caching with ElastiCache](https://www.internhack.in/roadmaps/tracks/cloud-engineer/elasticache) · Next: [APIs with API Gateway](https://www.internhack.in/roadmaps/tracks/cloud-engineer/api-gateway)

## More in Serverless and Event-Driven Architecture

- [AWS Lambda Functions](https://www.internhack.in/roadmaps/tracks/cloud-engineer/lambda)
- [APIs with API Gateway](https://www.internhack.in/roadmaps/tracks/cloud-engineer/api-gateway)
- [Decoupling with SQS, SNS and EventBridge](https://www.internhack.in/roadmaps/tracks/cloud-engineer/messaging-events)
- [Orchestrating Workflows with Step Functions](https://www.internhack.in/roadmaps/tracks/cloud-engineer/step-functions)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Cloud Engineer (AWS) Roadmap](https://www.internhack.in/roadmaps/tracks/cloud-engineer)
