Section: Exam Notes
Section: Practice Tests

Developing Code for AWS Lambda

This section focuses on Domain 1: Development with AWS Services, with an emphasis on Task 2: Developing code for AWS Lambda. Mastery of this area is essential, as Lambda is a core service tested across multiple exam scenarios involving serverless design, event handling, scalability, and error management.


Understanding Event Source Mapping in AWS Lambda

AWS Lambda supports multiple invocation models depending on how events are generated and delivered. These include synchronous invocations, asynchronous invocations, and polling-based event source mappings.

In synchronous invocations, the function is invoked directly and the caller waits for a response. Common examples include API Gateway, Application Load Balancer, CLI, and SDK calls. Asynchronous invocations are fully managed by AWS, where Lambda handles retries and failure handling automatically. Typical event sources include Amazon S3, Amazon SNS, and Amazon EventBridge. Polling-based invocations, also known as event source mappings, allow Lambda to continuously poll services such as Amazon SQS, DynamoDB Streams, and Amazon Kinesis and invoke the function when records are available.

Event source mapping is the mechanism that enables Lambda to automatically poll supported services and process records in batches. Configuration parameters such as BatchSize determine how many records are processed per invocation, while the Enabled flag controls whether the mapping is active.

Exam tips: Lambda polls SQS, Kinesis, and DynamoDB Streams automatically. Batch size directly affects throughput and error handling. For event-driven architectures, prefer SNS or EventBridge over polling-based services.


Stateless Applications in AWS Lambda

AWS Lambda functions are inherently stateless, meaning they do not retain data or execution context between invocations. Each execution is isolated, making Lambda ideal for horizontally scalable, serverless workloads.

To manage state in a stateless environment, external services must be used. Persistent data can be stored in DynamoDB or Amazon S3, while complex workflows that require state tracking should be orchestrated using AWS Step Functions. Temporary files can be stored in the /tmp directory, which provides up to 512 MB of ephemeral storage per execution environment.

Exam tips: Assume Lambda is stateless by default. Use DynamoDB or S3 for persistence and Step Functions for multi-step, stateful workflows.


Unit Testing AWS Lambda Functions

Testing Lambda functions is a key developer responsibility and is commonly assessed on the exam. The AWS Serverless Application Model (SAM) enables developers to run and test Lambda functions locally using tools such as sam local invoke.

A typical workflow involves writing the Lambda handler, creating unit tests using frameworks such as pytest or unittest, and executing tests locally before deployment. Keeping functions small, modular, and loosely coupled makes them easier to test and maintain.

Exam tips: Use AWS SAM for local testing. Favor modular Lambda functions with minimal dependencies. Python-based Lambda functions are commonly tested using pytest.


Event-Driven Architecture with AWS Lambda

Lambda is a foundational component of event-driven architectures, where functions are triggered automatically in response to events such as file uploads, database updates, or published messages. This approach decouples services and improves scalability and fault tolerance.

A common pattern involves Amazon SNS publishing messages that trigger Lambda functions asynchronously. Lambda then processes the event without blocking the publisher. For buffering and decoupling producers from consumers, Amazon SQS is often used. Amazon EventBridge is ideal for building large-scale, loosely coupled event-driven systems with custom event buses and routing rules.

Exam tips: Use SNS for fan-out patterns, SQS for message buffering, and EventBridge for complex event routing and integration.


Scaling AWS Lambda Functions

AWS Lambda automatically scales by running each invocation in a separate execution environment. As the incoming event rate increases, Lambda launches additional instances to handle the load.

Concurrency controls how many executions can run simultaneously. Reserved concurrency guarantees execution capacity for critical workloads and prevents other functions from consuming it. Provisioned concurrency keeps execution environments pre-initialized to reduce cold-start latency, making it ideal for low-latency APIs. Unreserved concurrency represents the default scaling behavior shared across functions.

Cold starts can be minimized by using provisioned concurrency, reducing deployment package size, and offloading dependencies to Lambda Layers. ARM-based Lambda runtimes can further reduce cost and startup time.

Exam tips: Provisioned concurrency reduces cold starts. Reserved concurrency prevents throttling of high-priority functions. Smaller packages lead to faster startup times.


Accessing Private Resources from Lambda Using VPCs

Lambda functions run outside a VPC by default. However, a VPC configuration is required when accessing private resources such as RDS databases, ElastiCache clusters, EC2 instances, or internal APIs.

When configured within a VPC, Lambda creates elastic network interfaces (ENIs) in the specified subnets. Security groups control traffic, and a NAT Gateway is required if the function needs outbound internet access. Appropriate IAM permissions must be granted to allow Lambda to create and manage network interfaces.

Exam tips: Lambda in a VPC requires subnets, security groups, and ENI permissions. Use a NAT Gateway for outbound internet connectivity.


Configuring AWS Lambda Functions

Lambda performance and reliability are influenced by configuration settings such as memory allocation, timeout values, and concurrency limits. Increasing memory also increases CPU allocation, which can significantly improve performance. Environment variables should be used for configuration data, while Lambda Layers help reduce deployment size by sharing common dependencies.

Exam tips: More memory equals more CPU. Set timeouts carefully to avoid premature failures. Use Layers to optimize deployment packages.


Handling Lambda Event Lifecycle and Errors

Error handling in Lambda depends on the invocation model. Synchronous invocations require the caller to handle errors and retries. Asynchronous invocations support automatic retries and can route failed events to Dead-Letter Queues (DLQs). Lambda Destinations provide more advanced routing options for both successful and failed executions.

Retry behavior varies by event source, making it essential to understand how different triggers handle failures.

Exam tips: Use DLQs for failed asynchronous events. Use Lambda Destinations for advanced error routing. Retry behavior differs for synchronous and asynchronous invocations.


Final Exam Takeaways

For the AWS Certified Developer – Associate exam, focus on knowing when to run Lambda inside a VPC, how event source mappings work, and how Lambda integrates into event-driven architectures. Be comfortable with scaling concepts such as concurrency and cold starts, and understand how to configure and troubleshoot Lambda functions using retries, DLQs, and Destinations.

Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Hide picture