SDLC Automation · Topic 4 of 6

Artifacts, Images and Packages

Build and manage artifacts with S3, CodeArtifact, Amazon ECR and EC2 Image Builder, including versioning, scanning, replication and golden AMI pipelines.

  • 5 min
In a nutshell
  • S3 versioning gives deployments an exact, recoverable revision.
  • CodeArtifact removes the need to run your own package repository and caches public packages through external connections.
  • Package origin controls defend against dependency confusion.

What it is

An artifact is anything a pipeline produces or consumes: a zip bundle, a library package, a container image or a machine image. Managing artifacts means storing them safely, versioning them, controlling who can use them and removing old ones.

AWS offers a different store for each kind. Amazon Simple Storage Service (S3) holds bundles, AWS CodeArtifact holds software packages, Amazon Elastic Container Registry (ECR) holds container images, and EC2 Image Builder produces Amazon Machine Images (AMIs).

PackagesCodeArtifactdependenciesBuildCodeBuildpushesImageECRruns onAMIfrom Image Builder

How it works

Bundles in S3

Pipeline and deployment bundles sit in S3. Turn on bucket versioning so a deployment can name an exact version, and use lifecycle rules to expire old objects. Encrypt with a customer managed KMS key when other accounts need access.

Packages in CodeArtifact

CodeArtifact is a managed package repository that works with common package managers such as npm, Maven, Gradle, pip, NuGet and others. A domain groups repositories and handles storage and encryption, and a repository holds the packages.

FeaturePurpose
Upstream repositoriesA repository can pull from another, so teams see one endpoint
External connectionLinks a repository to a public source such as npmjs or Maven Central and caches what is fetched
Package origin controlsLimit whether a package version may be published directly or arrive from upstream
Domain sharingPackages are stored once per domain, then used by many repositories

Package origin controls help prevent dependency confusion, where a public package with the same name as a private one is pulled by mistake. Build tools log in with a temporary authorization token.

aws codeartifact login --tool npm --domain my-domain --repository my-repo

Images in ECR

ECR stores container images in private or public repositories, with access controlled by IAM and repository policies.

aws ecr get-login-password --region us-east-1 | docker login --username AWS \
  --password-stdin 111122223333.dkr.ecr.us-east-1.amazonaws.com

Features worth knowing for the exam:

  • Image scanning: basic scanning checks for known vulnerabilities, and enhanced scanning uses Amazon Inspector for continuous results.
  • Tag immutability: blocks overwriting an existing tag, so v1.2.0 always means one image.
  • Lifecycle policies: expire old or untagged images automatically.
  • Replication: copies images to other Regions or accounts, which supports multi Region deployments and disaster recovery.
  • Pull through cache: caches images from supported public registries inside your private registry.

A lifecycle policy that removes untagged images after 14 days looks like this.

{
  "rules": [{
    "rulePriority": 1,
    "description": "Expire untagged images after 14 days",
    "selection": {
      "tagStatus": "untagged",
      "countType": "sinceImagePushed",
      "countUnit": "days",
      "countNumber": 14
    },
    "action": {"type": "expire"}
  }]
}

Tag images with the commit ID or a build number as well as a human friendly tag. Deploying latest makes rollbacks and audits unreliable.

Machine images with EC2 Image Builder

EC2 Image Builder automates building, testing and distributing AMIs and container images. You define the parts and a schedule, and it runs the build in a temporary instance.

PartRole
ComponentOne build or test step, such as installing a package or hardening the OS
Image recipeA base image plus an ordered list of components
Infrastructure configurationInstance type, subnet, security group and role for the build
Distribution settingsTarget Regions and accounts for the output AMI
Image pipelineTies them together and runs on a schedule or on demand
Baseparent imagerecipeBuildtemporary instancetests passAMIgolden imagedistributeRegionsand accounts

A golden AMI pipeline can start when a new parent image appears, build a patched AMI, and then trigger a CodePipeline or update a launch template. Publish the new AMI ID in Systems Manager Parameter Store, and let launch templates read the parameter, so instances pick up the new image without template edits.

Sharing and encryption

An encrypted AMI or snapshot can be shared with another account only if its KMS key is a customer managed key that the other account may use. Images encrypted with the AWS managed EBS key cannot be shared that way.

What to remember for the exam

  • S3 versioning gives deployments an exact, recoverable revision.
  • CodeArtifact removes the need to run your own package repository and caches public packages through external connections.
  • Package origin controls defend against dependency confusion.
  • ECR offers scanning, tag immutability, lifecycle policies and cross Region or cross account replication.
  • Use ECR lifecycle policies, not custom scripts, to clean old images.
  • EC2 Image Builder builds, tests and distributes AMIs on a schedule with no custom servers.
  • Store the latest approved AMI ID in Parameter Store and reference it from launch templates.
  • Sharing encrypted AMIs across accounts needs a customer managed KMS key.
Exam tip

When a question wants the same container image in two Regions with the least effort, pick ECR replication before writing a copy script.

Common mistakes

Pulling dependencies straight from the internet in every build. This is slow and exposes you to removed or tampered packages, whereas CodeArtifact keeps a controlled copy.

Using mutable tags such as latest in production. Two deploys of the same tag can run different code.

Forgetting repository cleanup. Images and artifacts pile up with no lifecycle rule and costs grow.

Baking secrets into an AMI or image. Anyone with access to the image can read them, so fetch secrets at runtime.

Watch out

An AMI built once and never rebuilt falls behind on security patches, so schedule the Image Builder pipeline to rebuild regularly.

Check yourself

  • Which feature protects against a public package replacing a private package with the same name?

    CodeArtifact package origin controls, which restrict whether versions may come from upstream or be published directly.

  • How do you keep ECR from filling up with old images?

    Add an ECR lifecycle policy that expires untagged or old images automatically.

  • What stops an image tag from being overwritten?

    Turning on tag immutability for the ECR repository.

Topic 4 of 6 in SDLC Automation

Test yourself on SDLC Automation

The full AWS DOP-C02 question bank has 844 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.