Practice Questions
AWS Lambda
Lambda is a serverless compute service. You provide code; AWS provisions and manages all execution infrastructure. You are billed only for the duration your code runs (in 1ms increments).
Execution Model
- Invocation types: synchronous (caller waits for a response), asynchronous (Lambda queues the request and returns immediately), and event source mapping (Lambda polls a source like SQS or DynamoDB Streams)
- Execution environment: Lambda creates and reuses execution environments (containers). Subsequent invocations may reuse a warm environment (/tmp storage persists between warm invocations; in-memory variables are reset on cold starts)
- Cold start: the time required to initialize a new execution environment when no warm environment is available; can add milliseconds to hundreds of milliseconds of latency for the first invocation
- Provisioned concurrency: pre-initializes a specified number of execution environments to eliminate cold starts; useful for latency-sensitive applications
Concurrency
- Concurrency = number of Lambda executions running simultaneously
- Account-level concurrency limit: 1,000 by default across all functions in a region (can be increased)
- Reserved concurrency: sets a cap on a specific function's maximum concurrency; prevents one function from consuming all available concurrency
- Unreserved concurrency: the pool available to functions without a reserved concurrency setting
Lambda in VPCs
By default, Lambda functions run outside your VPC and cannot access private VPC resources (RDS, ElastiCache, private EC2).
- To access private VPC resources, configure the Lambda function with VPC settings (specify subnets and security groups)
- Lambda in a VPC requires NAT Gateway to reach the internet (the VPC doesn't have internet access by default)
- Lambda + VPC adds cold start latency but that overhead has been significantly reduced in recent years
Key Configuration
- Timeout: max execution time per invocation; 3 seconds by default, up to 15 minutes