Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
AWS · DVA-C03

Configuring Lambda functions

DVA-C03 · Lesson 6 of 24 · 48:53

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the DVA-C03 exam (AWS Certified Developer – Associate). In this lesson: the handler and initialization code, environment variables, memory and CPU, timeouts, ephemeral storage in the tmp folder, layers, extensions, and VPC access with endpoints. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

A function that timed out

AnyCompany Tickets has a function that builds the PDF of each ticket after an order. Its first version timed out after three seconds, and it could not reach the orders database, which sits in a private subnet. This lesson covers how to configure a Lambda function: its handler and environment variables, its memory, timeout, and storage, its layers and extensions, and its access to a VPC.

Handler and environment variables

The handler is the entry point of the function, named after the file and the function, like app dot handler. It receives the event, with the data to process, and a context object, with details on the invocation. Code outside the handler runs once per execution environment and is reused by the next invocations, so create SDK clients and database connections there. Environment variables hold settings like a table name or a log level, read by the code at run time, with a total of four kilobytes. Lambda encrypts them at rest, with a key of your choice if needed, but secrets belong in Secrets Manager, as lesson thirteen shows.

Memory, timeout, and storage

Memory goes from 128 megabytes to 10,240 megabytes, and Lambda allocates CPU power in proportion: at 1,769 megabytes, a function has the equivalent of one virtual CPU. So more memory often makes a compute-heavy function faster, and sometimes cheaper. The timeout is three seconds by default, and can go up to 900 seconds, which is fifteen minutes. The tmp folder gives ephemeral storage, from 512 megabytes up to 10,240. And work that takes longer than fifteen minutes belongs in a Step Functions workflow, or in Lambda durable functions, which can run for up to a year.

Layers and extensions

A layer is a zip archive with libraries, a custom runtime, or data, that Lambda unpacks into the opt folder. A function can use up to five layers, and several functions can share one, so a common library is packaged once and versioned. A zip package and its layers must fit in 250 megabytes unzipped, while a container image can reach ten gigabytes, and puts its libraries in the image instead of layers. Extensions run in the same execution environment, to add monitoring, security, or configuration tools. An internal extension runs in the runtime process, and an external one runs as a separate process, even in another language.

Access to a VPC

To reach private resources, like a database, attach the function to private subnets of the VPC, with a security group. Lambda creates Hyperplane network interfaces, shared by the functions with the same subnets and security groups, and the execution role needs permissions to manage them, as in the managed policy for VPC access. The database's security group must allow traffic from the function's security group. A VPC-connected function has no internet access by default, and a public subnet does not give it one: it needs a NAT gateway. And for AWS services, VPC endpoints keep the traffic private, like a gateway endpoint for DynamoDB or S3.

Which setting to change

Each symptom points to a setting. A slow, compute-heavy function needs more memory, and a function that waits on other services needs a longer timeout. Large temporary files need more ephemeral storage, and settings that differ between environments go in environment variables. Shared libraries go in a layer, and private resources call for VPC access. In the Lambda documentation, these classic functions are now called Lambda Event Functions, while the exam just says Lambda functions.

Recap

Let's recap. The handler receives the event and the context, and code outside it is reused, so clients and connections belong there. Environment variables hold settings, up to four kilobytes, and secrets go to Secrets Manager. Memory sets CPU power, the timeout goes up to fifteen minutes, and the tmp folder up to ten gigabytes. Layers share libraries across functions, and extensions add tools beside the code. And private subnets with a security group reach private resources, while a NAT gateway or VPC endpoints give the way out.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. A function with default settings calls a partner API that takes about eight seconds to answer. Every invocation fails with a timeout error, and CloudWatch shows almost no CPU use. What should the developer change first?

    • Raise the memory to 10,240 MB
    • Raise the ephemeral storage to 10 GB
    • Turn on provisioned concurrency
    • Raise the timeout above eight seconds
    Show the answer

    Raise the timeout above eight seconds

    The function waits on the partner, so it needs a timeout longer than eight seconds, instead of the default three. “Raise the memory to 10,240 MB” would add CPU power, and the partner would still take eight seconds. “Raise the ephemeral storage to 10 GB” would give more disk space, which is not the problem. And “Turn on provisioned concurrency” would keep idle environments ready, without making the call any shorter.

  2. A function attached to private subnets reads the orders database without trouble, but its calls to a DynamoDB table now time out. The VPC has no NAT gateway, and the traffic must stay private. What should the developer add?

    • A gateway VPC endpoint for DynamoDB
    • A public subnet for the function
    • More memory for the function
    • A resource-based policy on the table
    Show the answer

    A gateway VPC endpoint for DynamoDB

    A gateway VPC endpoint for DynamoDB gives the private subnets a private route to the service. “A public subnet for the function” would not help, since a public subnet gives the function no public address. “More memory for the function” would add CPU power, and the calls would still have no route. And “A resource-based policy on the table” would be about permissions, while the calls never reach the table.

  3. Twelve functions use the same in-house library to format tickets. Today, each deployment package contains its own copy, and an update means rebuilding all twelve. What should the developer do?

    • Run the library as an extension
    • Store the library in environment variables
    • Package the library as a layer
    • Copy the library into each container image
    Show the answer

    Package the library as a layer

    A layer packages the library once, and each function points to the version that it uses. “Run the library as an extension” would only add a hook to each function's run, without sharing any code. “Store the library in environment variables” would hold settings, with a total of four kilobytes, and no code. And “Copy the library into each container image” would keep twelve copies, which is the problem to solve.