0%
AWS Developer Associate (DVA-C03) Exam Prep: Development, Security, Testing, Deployment and Troubleshooting
How the Exam Works
Domain 1: Development with AWS Services
Domain 2: Security
Domain 3: Testing and Deployment
Domain 4: Troubleshooting and Optimization
Final Review and Mock Exams
Containers for Developers: ECR, ECS, EKS and Fargate
Containers arrived in the developer exam as a first class topic with the C03 version of the guide. Skill 3.1.2 asks you to build and manage container images, which means Dockerfiles, tagging, Amazon ECR and lifecycle policies. Skill 3.3.2 asks you to deploy containerized applications with ECS task definitions, EKS manifests, the Fargate launch type and rolling updates. Pieces of other skills touch containers too: packaging artifacts, testing in environments, deploying code and checking workload health with health checks and probes. This lesson covers all of it from the point of view of the person who writes the code and the Dockerfile, not the person who runs the cluster.
Several neighbouring lessons own related material, and this one refers to them rather than repeating them. The CI/CD lesson covers CodeBuild, buildspec phases and CodePipeline, including the build commands that log in to ECR and push. The infrastructure as code lesson covers CloudFormation, SAM and CDK, which is where task definitions and services usually live in real projects. The deployment strategies lesson covers rolling, blue green, canary and linear in depth, including ECS blue green through CodeDeploy and the appspec hooks. The monitoring lesson covers CloudWatch Logs, metrics, alarms and X-Ray. Here you learn what goes inside the image, how it gets to ECR, and how ECS and EKS run it.
Images, layers and the build cache
A container image is a stack of read only layers plus a small JSON manifest and configuration. Each instruction in a Dockerfile that changes the filesystem, such as RUN, COPY or ADD, produces a layer. When you run a container, the runtime adds a thin writable layer on top. Two images built from the same base share the base layers, so a registry stores them once and a host downloads them once.
The build cache reuses a layer if the instruction and its inputs have not changed since the last build. As soon as one layer changes, every layer after it is rebuilt. That rule decides the order of a good Dockerfile: put the things that change least at the top and the things that change most at the bottom. Dependencies change less often than source code, so copy the dependency manifest and install dependencies first, then copy the source.
A .dockerignore file keeps the build context small and the cache stable. Without one, COPY . . sends your .git directory, local node_modules, test output and possibly a .env file with real credentials into the build, and any change to those files invalidates the cache. List them in .dockerignore so they never reach the build at all.
Choosing a base image
The base image in the FROM line sets the size, the attack surface and the patching burden of everything built on it. A full operating system image with compilers and shells is convenient while you experiment but ships hundreds of packages you never call, each one a potential vulnerability that the scanner in section two will report. Smaller choices exist for most languages: slim variants of the official language images, minimal images such as the Amazon Linux 2023 minimal container image, Alpine based images and distroless images that contain only the language runtime and its libraries, with no shell or package manager.
Each has a trade off. Alpine uses musl instead of glibc, which occasionally breaks native modules and changes performance characteristics. Distroless images are excellent for production but have no shell, so you cannot exec into the container to poke around, which pushes you towards good logging. Slim images are a safe middle ground. Pin the base image to a specific version tag, or better a digest, so a rebuild next month does not silently pick up a new major version.
Where you pull the base image from matters too. Pulling anonymously from Docker Hub in a busy build system can hit Docker Hub's pull rate limits and fail builds. Many official images are mirrored in the ECR Public Gallery at public.ecr.aws, and ECR pull through cache, covered in section two, can keep a copy in your own registry.
Multi stage builds
A multi stage build uses more than one FROM line in one Dockerfile. The first stage has everything needed to build: the SDK, compilers, test tools and the full dependency tree. A later stage starts from a small runtime image and copies only the finished artifact out of the earlier stage with COPY --from. The final image is the last stage, and nothing from the earlier stages ships unless you copy it.
The benefit is large and measurable. A Java build image with Maven is often close to a gigabyte, while the runtime image is a fraction of that. Smaller images pull faster, which shortens task start time on Fargate and cold starts for Lambda container images, and they contain fewer packages to patch. When a question asks how to reduce image size or remove build tools from a production image without changing the application, a multi stage build is the answer.
Running as a non root user
By default, a container process runs as root inside the container. Containers share the host kernel, so a process that escapes its container as root is far more dangerous than one that escapes as an unprivileged user. The fix is cheap: create a user in the image and switch to it with the USER instruction, preferably by numeric UID so that platforms can check it is not zero.
Two consequences follow. An unprivileged user cannot bind ports below 1024 by default, so the application listens on a high port such as 8080 and the load balancer or Service maps traffic to it. And the user must be able to read the application files and write to whatever paths the application writes, so set ownership when you copy. Going further, ECS container definitions support readonlyRootFilesystem, and Kubernetes supports runAsNonRoot and readOnlyRootFilesystem in the security context, which make the platform refuse to run an image that breaks the rule.
Configuration and secrets stay out of the image
An image should be the same artifact in every environment. The database host, log level and feature switches belong in environment variables that the task definition or Kubernetes manifest provides at run time, and passwords and API keys belong in Secrets Manager or Parameter Store, injected at start. Section three shows how.
Never put a secret in a build argument or an ENV line. Build arguments and environment values are recorded in the image history and configuration, so anyone who can pull the image can read them, and deleting the file in a later layer does not remove it from the earlier layer. If the build itself needs a secret, for example a token for a private package registry, use a BuildKit secret mount, which makes the secret available to one RUN step without writing it to any layer.
Architecture, entrypoints and signals
Images are built for a CPU architecture. Fargate, ECS on EC2, EKS and Lambda all support both x86_64 and arm64, and Graviton based arm64 capacity is usually cheaper for the same work. An image built on an Apple silicon laptop is arm64 by default; deploy it to x86_64 tasks and it fails with an exec format error. Build for the target explicitly with docker buildx build --platform linux/amd64, or build a multi architecture image index for both. On ECS you choose the architecture in the task definition's runtimePlatform. Lambda is stricter: the image must target exactly one architecture and match the function's setting.
Use the exec form of ENTRYPOINT and CMD, the JSON array form, rather than the shell form. In the exec form your process is PID 1 and receives SIGTERM directly when ECS or Kubernetes stops the container, so it can finish in flight requests and close connections. In the shell form, a shell is PID 1 and may not forward the signal, so the platform waits out its stop timeout and then kills the process with SIGKILL. ENTRYPOINT names the executable; CMD supplies default arguments that a task definition's command or a Kubernetes args field can override.
What the exam is checking
Image questions test a few ideas. Smaller and safer images come from slim bases and multi stage builds. Cache efficiency comes from ordering instructions by how often they change. Secrets never live in the image. Containers should not run as root. And images must match the architecture of the compute that runs them. If you can explain why each of those matters, the scenario questions become recognition exercises.
Run docker history on an image you built and read every layer. If you see a large layer you did not expect, a copied .git directory or a secret in an ENV line, you have found the first thing to fix, and you will recognise the same mistakes in exam options.