Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
AWS · DVA-C03

Packaging code and container images

DVA-C03 · Lesson 15 of 24 · 2:08:11

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: zip packages and their limits, dependencies built for the function's platform, layers, container images for Lambda, image tags and digests, and Amazon ECR with tag immutability, lifecycle policies, and image scanning. Includes three original practice questions.

Study notes

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

A package that grew

At AnyCompany Tickets, the pricing function grew to a ninety megabyte archive, and its upload from the CLI started to fail. Five other functions each bundle the same libraries, and a build overwrote the image tag that production used, so nobody knew which code was running. This lesson covers zip packages, layers, container images, and Amazon ECR.

Zip packages

A zip archive holds the code and its dependencies, built for the runtime and the architecture of the function. Uploaded directly, through the API or the SDK, the archive can be up to fifty megabytes, and larger archives go through an S3 bucket. Unzipped, the code, its dependencies, and its layers are limited to two hundred fifty megabytes together. And settings that change between environments stay out of the package, in environment variables, up to four kilobytes in total.

Dependencies

Every dependency goes in the package, at an exact version, from a requirements file, so that each build gives the same result. The Python runtime includes the SDK, but AWS changes that version over time, so AWS recommends that you package the SDK version that you tested. Libraries with native code must match the architecture of the function, x86 or arm64, so download the wheels built for Linux on that platform. Small packages also deploy faster, and start faster.

Layers

A layer is a zip archive of libraries, a custom runtime, or other files that several functions share. A function can have up to five layers, and Lambda unpacks their content into the slash opt directory. Each layer version is an immutable snapshot with its own ARN, and a function keeps the exact version that it references, until you change it. Layers keep packages small, but they count toward the limit of two hundred fifty megabytes, and only zip functions can have them.

Container images

A function can also be a container image, of up to ten gigabytes, stored in an ECR repository in the same Region. An AWS base image for Lambda brings the runtime, the runtime interface client, and the runtime interface emulator, to test the image locally. With an operating system only base image, or any other base image, you add the runtime interface client yourself. The image must be a Linux image, built for one architecture only, and it runs on a read-only file system, with a writable slash temp directory. And the Dockerfile copies the requirements, installs them, copies the code, and names the handler.

From build to function

To ship an image, build it for the platform of the function, then log in to ECR with get login password, then tag the image and push it. Lambda resolves the tag to the digest of the image when you deploy, so pushing a new image under the same tag changes nothing: you must deploy the image to the function again. After each deployment, the function stays pending for a few seconds, while Lambda optimizes the image. And the package type of a function is fixed: a zip function cannot become an image function.

Tags in ECR

In an ECR repository, each image has a digest, and one or more tags. A tag like latest moves to every new image, so production should deploy a precise tag, like a release number or a commit ID, or the digest itself. Tag immutability blocks the reuse of a tag: a push with an existing tag fails. And exclusion filters can keep a few tags mutable, like latest, with every other tag protected.

Lifecycle policies

Lifecycle policies keep repositories clean. Each rule has a priority, selects images by tag status or by tag prefix, and expires them or archives them: for example, untagged images after fourteen days, or all but the last thirty release images. Preview the rules before you apply them, since images are expired within twenty-four hours of matching. And image scanning finds known vulnerabilities, with basic scanning on each push, or enhanced scanning that runs continuously.

Recap

Let's recap. A zip package is up to fifty megabytes through the API, larger through S3, and two hundred fifty megabytes unzipped with its layers. Dependencies are packaged at exact versions, the SDK included, for the right architecture. Layers share libraries between zip functions, up to five, as immutable versions. Container images go up to ten gigabytes in ECR, from a base image with the runtime interface client, and the package type of a function never changes. And ECR protects tags with immutability, and cleans up with lifecycle policies.

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. The deployment package of a function is now a 90 MB .zip file, and its upload from the CLI fails. Unzipped, the package is 200 MB. What should the developer do?

    • Split the code into two archives of 45 MB
    • Raise the memory setting of the function
    • Upload the .zip file to S3, then point the function to it
    • Move the dependencies into environment variables
    Show the answer

    Upload the .zip file to S3, then point the function to it

    An archive larger than fifty megabytes goes through an S3 bucket, and two hundred megabytes unzipped stays under the limit. “Split the code into two archives of 45 MB” would not work, because a function has a single deployment package. “Raise the memory setting of the function” would add memory and CPU, without changing the upload limit. And “Move the dependencies into environment variables” would hit the limit of four kilobytes for all the environment variables of a function.

  2. A function was created from a .zip file. The team now wants to deploy it as a container image, built with its own tools. What must the developer do?

    • Create a new function from the container image
    • Change the package type in the function settings
    • Publish the image as a new layer of the function
    • Publish a new version that points to the image
    Show the answer

    Create a new function from the container image

    The package type of an existing function cannot change, so the image needs a new function. “Change the package type in the function settings” is not possible, since Lambda has no setting to switch the type. “Publish the image as a new layer of the function” would not work, because a layer is a zip archive, and image functions have no layers. And “Publish a new version that points to the image” would keep the same package type, since a version is a snapshot of the function.

  3. A build pushed a new image under a release tag that production already used, and nobody could tell which image was running. A tag must never move again. What should the developer configure?

    • A lifecycle policy that expires untagged images
    • Scan on push for the repository
    • The latest tag for every deployment
    • Tag immutability on the repository
    Show the answer

    Tag immutability on the repository

    With tag immutability, a push that reuses an existing tag fails, so each tag keeps its image. “A lifecycle policy that expires untagged images” would clean up old images, while tags could still move. “Scan on push for the repository” would look for vulnerabilities, without protecting any tag. And “The latest tag for every deployment” would be the opposite, since latest moves with every push.