AWS Lambda Functions
- Each function has associated configuration information, such as its name, description, runtime, entry point, and resource requirements
- Lambda functions should be designed as stateless
- Lambda Execution role can be assigned to the function to grant permission to access other resources.
- Functions have the following restrictions
- Inbound network connections are blocked
- Outbound connections only TCP/IP sockets are supported
ptrace(debugging) system calls are blocked- TCP port 25 traffic is also blocked as an anti-spam measure.
- Lambda may choose to retain an instance of the function and reuse it to serve a subsequent request, rather than creating a new copy.
- Lambda Layers provide a convenient way to package libraries and other dependencies that you can use with your Lambda functions.
- Function versions can be used to manage the deployment of the functions.
- Function Alias supports creating aliases, which are mutable, for each function version.
- Functions have the following limits
- RAM – 128 MB to 10,240 MB (10 GB)
- CPU is linked to RAM and cannot be set manually.
- 2 vCPUs = 1769 MB RAM
- 6 vCPUs = 10240 MB RAM
- Timeout – 900 Secs or 15 mins
/tmpstorage between 512 MB and 10,240 MB- Deployment Package – 50 MB (zipped), 250 MB (unzipped) including layers
- Concurrent Executions – 1000 (soft limit)
- Container Image Size – 10 GB
- Invocation Payload (request/response) – 6 MB (sync), 1 MB (async)
- Functions are automatically monitored, and real-time metrics are reported through CloudWatch, including total requests, latency, error rates, and throttled requests.
- Lambda automatically integrates with CloudWatch logs, creating a log group for each function and providing basic application lifecycle event log entries, including logging the resources consumed for each use of that function.
- Lambda supports Advanced Logging Controls that allow configuring JSON structured logging, log-level filtering, and choosing which CloudWatch log group to send logs to.
- Functions support code written in
- Node.js (JavaScript) – Node.js 22, Node.js 24
- Python – Python 3.12, 3.13, 3.14
- Ruby – Ruby 3.3, 3.4, 4.0
- Java – Java 21, Java 25
- .NET – .NET 8, .NET 10
- Go (via OS-only runtime on Amazon Linux 2023)
- Rust (via OS-only runtime)
- Custom runtime (provided.al2023)
- Container images are also supported.
- All supported runtimes support both x86_64 and arm64 (Graviton) architectures.
- Failure Handling
- For S3 bucket notifications and custom events, Lambda will attempt execution of the function three times in the event of an error condition in the code or if a service or resource limit is exceeded.
- For ordered event sources that Lambda polls, e.g. DynamoDB Streams and Kinesis streams, it will continue attempting execution in the event of a developer code error until the data expires.
- Kinesis and DynamoDB Streams retain data for a minimum of 24 hours
- Dead Letter Queues (SNS or SQS) can be configured for events to be placed, once the retry policy for asynchronous invocations is exceeded
- Recursive Loop Detection is enabled by default. Lambda detects recursive loops between Lambda and supported services (SQS, SNS, S3) and stops function invocation after 16 iterations to prevent unintended usage and billing.
Lambda Layers
- Lambda Layers provide a convenient way to package libraries and other dependencies that you can use with your Lambda functions.
- Layers help reduce the size of uploaded deployment archives and make it faster to deploy your code.
- A layer is a .zip file archive that can contain additional code or data.
- A layer can contain libraries, a custom runtime, data, or configuration files.
- Layers promote reusability, code sharing, and separation of responsibilities so that you can iterate faster on writing business logic.
- Layers can be used only with Lambda functions deployed as a .zip file archive.
- For functions defined as a container image, the preferred runtime and all code dependencies can be packaged when the container image is created.
- A Layer can be created by bundling the content into a .zip file archive and uploading the .zip file archive to the layer from S3 or the local machine.
- Lambda extracts the layer contents into the
/optdirectory when setting up the execution environment for the function.
Environment Variables
- Environment variables can be used to adjust the function’s behavior without updating the code.
- An environment variable is a pair of strings that are stored in a function’s version-specific configuration.
- The Lambda runtime makes environment variables available to the code and sets additional environment variables that contain information about the function and invocation request.
- Environment variables are not evaluated prior to the function invocation.
- Lambda stores environment variables securely by encrypting them at rest.
- AWS recommends using Secrets Manager instead of storing secrets in the environment variables.
Lambda Function Limits
- RAM – 128 MB to 10,240 MB (10 GB)
- CPU is linked to RAM and cannot be set manually.
- 2 vCPUs = 1769 MB RAM
- 6 vCPUs = 10240 MB RAM
- Timeout – 900 Secs or 15 mins
/tmpstorage between 512 MB and 10,240 MB- Deployment Package – 50 MB (zipped), 250 MB (unzipped) including layers
- Concurrent Executions – 1000 (soft limit)
- Container Image Size – 10 GB
- Invocation Payload (request/response) – 6 MB (sync), 1 MB (async)
- Response Streaming Payload – 200 MB
Lambda Scaling
- Lambda scales by 1,000 concurrent executions every 10 seconds (12x faster than previous scaling).
- Each function scales independently from other functions in the same account.
- Default account concurrency limit is 1,000 concurrent executions (soft limit, can be raised).
- Reserved Concurrency sets both the maximum and minimum concurrent instances for a function. No other function can use that reserved capacity.
- Provisioned Concurrency pre-initializes execution environments to provide double-digit millisecond response times with no cold starts.
Lambda SnapStart
- Lambda SnapStart is an opt-in performance optimization that reduces cold start latency from several seconds to as low as sub-second, typically with no code changes.
- SnapStart takes a snapshot of the initialized execution environment (memory and disk state), caches it, and reuses it to rapidly start new environments.
- Supported for Java, Python, and .NET runtimes.
- Eliminates the need for complex performance optimizations or provisioned concurrency for cold-start-sensitive workloads.
- SnapStart cannot be used simultaneously with Provisioned Concurrency on the same function version.
Lambda Function URLs
- A function URL is a dedicated HTTP(S) endpoint for a Lambda function.
- Function URLs can be created without the need for API Gateway or an Application Load Balancer.
- Support AWS_IAM auth type for authenticated access or NONE for public access.
- Support CORS configuration for cross-origin requests.
- Function URLs support response streaming, enabling progressive delivery of responses to clients.
- Suitable for single-function microservices, webhooks, and simple APIs that don’t require API Gateway features.
Lambda Response Streaming
- Response streaming allows functions to progressively stream response payloads back to clients as data becomes available.
- Improves time-to-first-byte (TTFB) latency for web applications and LLM-based applications.
- Supports response payloads up to 200 MB (10x higher than buffered responses).
- Available through Lambda function URLs or the
InvokeWithResponseStreamAPI. - Well suited for AI/ML inference, real-time data processing, and generating large files or reports.
Lambda Durable Functions
- Durable functions extend the Lambda programming model for building reliable multi-step applications and AI workflows.
- Automatically checkpoint progress, suspend execution for up to one year, and recover from failures without custom state management code.
- Use new primitives in the event handler such as steps (for checkpointing) and waits (for pausing execution).
- No compute charges during suspended wait periods for on-demand functions.
- Supported for Python and Node.js runtimes.
- Use cases include AI agent orchestration, human-in-the-loop workflows, multi-step order processing, and long-running data pipelines.
- Can be integrated with AWS Step Functions for complex orchestration scenarios.
Lambda Managed Instances
- Lambda Managed Instances (LMI) lets you run Lambda functions on Amazon EC2 instances while maintaining Lambda’s operational simplicity.
- AWS manages infrastructure operations including instance lifecycle management, OS patching, runtime updates, request routing, load balancing, and auto-scaling.
- Provides access to specialized compute configurations including Graviton4, network-optimized, and memory-optimized instances.
- Supports up to 32 GB of memory and 16 vCPUs per function (3x more memory than standard Lambda).
- Enables multi-concurrent invocations per execution environment (multiple requests handled simultaneously).
- Provides access to EC2 pricing models including Compute Savings Plans and Reserved Instances (up to 72% discount over On-Demand).
- Supports over 400 EC2 instance types from general purpose, compute-optimized, and memory-optimized families.
- Ideal for compute-intensive workloads such as media transcoding, scientific simulations, and large-scale data processing.
Lambda Functions Versioning
- Function versions can be used to manage the deployment of the functions.
- Each function has a single, current version of the code.
- Lambda creates a new version of the function each time it’s published.
- A function version includes the following information:
- The function code and all associated dependencies.
- The Lambda runtime that invokes the function.
- All the function settings, including the environment variables.
- A unique Amazon Resource Name (ARN) to identify the specific version of the function.
- Function versions are immutable, however, support Aliases which are mutable.
Lambda Functions Alias
- Lambda supports creating aliases, which are mutable, for each function version.
- Alias is a pointer to a specific function version, with a unique ARN.
- Each alias maintains an ARN for a function version to which it points.
- An alias can only point to a function version, not to another alias
- Alias helps in rolling out new changes or rolling back to old versions
- Alias supports routing configuration to point to a maximum of two Lambda function versions. It can be used for canary testing to send a portion of traffic to a second function version.
One thought on “AWS Lambda Functions”
Comments are closed.