Ref: https://learn.cantrill.io/courses/1820301/lectures/41301391
DEMO: https://learn.cantrill.io/courses/1820301/lectures/41301395
AWS Lambda - Key Concepts
- 🔧 Function-as-a-Service (FaaS) → specialized, short-running, focused code
- Lambda function = a piece of code that Lambda runs
- Unit of configuration in AWS Lambda
- 💡 ”A Lambda” = “A Lambda function” (colloquially)
- A function must specify a Runtime Environment (RTE) before execution (e.g. Python 3.8)
- ‼️ RTE memory is DIRECTLY allocated/configured! → vCPU INDIRECTLY allocated
- When triggered, function is loaded and executed in the specified RTE
- ❗ Billed only for consumed compute during function execution
- Key part of serverless and/or event-driven architectures (EDAs) in AWS
- 💡 Usually Lambda is a really cheap service: first million invocations fall into free tier, and further invocations are cheap → AWS Lambda is a very popular service, especially for smaller deployments
AWS Lambda - Architecture

- 🔧 Lambda Function, strictly speaking, is code + configuration + wrappings
- Must define: programming language of the code + Deployment Package (which Lambda downloads & executes at runtime) + set resources
- 💡 Colloquially, a Lambda function might refer to only the code, but the whole package is much more than just the code. Think how an AMI is more than just a VM image
- Many Runtimes (RTs) & languages supported: Python, Ruby, Java, Node.js…
- Lambda Layers allow creating custom RTs, e.g. Rust (supported by community)
- Select RTE = select the RTE components available inside the environment
- e.g. Python code requires certain version & modules of Python to be installed
- Every time a function is invoked/executed, a new RTE with all its components is created
- Code loaded, code executed, then function terminates
- Next invocation(s) will generally create a brand new RTE (there are exceptions)
- ❗ Some configurations can make further invocations reuse components or data from previous RTEs, or different functions to use the same RTE, but this is NOT the default!
- 🔧 Functions/RTEs are stateless → no data is left over from previous invocation (generally)
- Stateless architecture must be assumed! → Code must always be able to run & function properly in a brand new RTE
- ‼️ Docker is an anti-pattern for Lambda!!
- Docker generally means traditional containerized computing → i.e. using a Docker image to spin up a container that runs in a containerized compute environment (e.g. ECS)
- In exam, assume Docker means not Lambda!
- ‼️ Lambda DOES support Docker images, but it's a different process!!
- You can use standard Docker/container build processes to create Lambda images (designed to run inside the Lambda environment)
- Do NOT confuse Docker container images with Docker images used for Lambda (i.e. Lambda images)!
- Defined resources:
- Memory: 128MB-10240MB, in 1MB steps (directly allocated)
- vCPU: 1vCPU per 1769MB of memory (linear)
- Scales with memory → NOT allocated/controlled directly
- Disk allocation: 512MB storage available by default → mounted in
/tmp
- Can have up to 10240MB
- ❗ Assume it's blank every time a function is invoked! → should only be viewed as temporary space
- ‼️ Function timeout = 900s = 15mins!!!
- For anything beyond 15mins, can't use Lambda directly! → need e.g. AWS Step Functions