Build and Manage Artifacts: AWS DevOps Professional Study Guide
Build and manage artifacts
Build and Manage Artifacts
This guide covers the essential knowledge for Domain 1 of the AWS Certified DevOps Engineer - Professional exam, focusing on the creation, storage, and lifecycle management of software artifacts.
Learning Objectives
By the end of this study guide, you should be able to:
- Configure AWS CodeBuild to produce artifacts using
buildspec.yml. - Identify the appropriate repository for different artifact types (S3, CodeArtifact, ECR).
- Implement secure artifact management using IAM and encryption.
- Automate the creation of golden images using EC2 Image Builder.
- Manage the artifact lifecycle, including versioning and retention.
Key Terms & Glossary
- Artifact: A deployable software package (e.g., .zip, .jar, Docker image) produced during the build phase.
- Buildspec: A YAML file used by AWS CodeBuild to define build commands and artifact locations.
- AWS CodeArtifact: A fully managed artifact repository service for software packages (npm, maven, pip, etc.).
- Amazon ECR (Elastic Container Registry): A managed Docker container registry.
- Golden Image: A pre-configured snapshot of an EC2 instance or container used as a template.
The "Big Idea"
Artifact management serves as the critical handoff point between Continuous Integration (CI) and Continuous Deployment (CD). In a professional DevOps environment, artifacts must be immutable, versioned, and securely stored. If the build process is the engine, the artifact is the fuel; it must be refined, labeled, and protected from contamination to ensure the deployment environment remains stable and predictable.
Formula / Concept Box
| Buildspec Phase | Purpose | Typical Commands |
|---|---|---|
install | Set up the runtime environment | runtime-versions: java: corretto11 |
pre_build | Sign in to registries / Install deps | aws ecr get-login-password... |
build | Compile and test code | mvn install or npm run build |
post_build | Package and cleanup | docker tag ... |
artifacts | Define output files for S3 | files: - '**/*' |
Hierarchical Outline
- Generating Artifacts with AWS CodeBuild
- Build Environment: Managed containers (Java, Python, Go, etc.) or custom Docker images.
- buildspec.yml: Must be in the root directory. Defines phases and the
artifactsblock. - Environment Variables: Use SSM Parameter Store or Secrets Manager for sensitive data.
- Artifact Repositories
- Amazon S3: Best for static assets, deployment zips, and Lambda packages.
- AWS CodeArtifact: Best for internal library sharing (Maven, NuGet, npm, PyPI).
- Amazon ECR: Dedicated registry for Docker and OCI-compliant images.
- Automated Image Building
- EC2 Image Builder: Automates the creation, patching, and distribution of AMIs.
- Workflow: Source Image → Build Components → Test Components → Distribution.
- Security & Lifecycle
- Access Control: Use IAM roles for CodeBuild and Resource-based policies for S3/ECR.
- Lifecycle Policies: Automatically expire old ECR images or transition S3 objects to Glacier.
Visual Anchors
CI/CD Artifact Flow
Artifact Lifecycle Stages
Definition-Example Pairs
- Immutable Artifact: An artifact that is never modified after creation. If a change is needed, a new version is built.
- Example: Instead of updating a running server, you build a new Docker image (
v2) and replace the old container (v1).
- Example: Instead of updating a running server, you build a new Docker image (
- Artifact Mapping: Defining which files from the build environment are preserved.
- Example: In
buildspec.yml, mapping thetarget/*.jarfolder to be uploaded to S3 while discarding temporary.logfiles.
- Example: In
- Upstream Repository: A repository in CodeArtifact that provides packages to a downstream repository.
- Example: An internal
team-repousingnpmjs-store(public npm) as an upstream to cache and control external dependencies.
- Example: An internal
Worked Examples
Java Maven buildspec.yml for CodeDeploy
version: 0.2
phases:
install:
runtime-versions:
java: corretto11
build:
commands:
- mvn package
artifacts:
files:
- target/my-app.jar
- appspec.yml
- scripts/**/*
discard-paths: yesExplanation:
- The
installphase ensures the Correcto 11 JDK is available. - The
buildphase runs Maven to create the JAR file. - The
artifactsblock selects the JAR, theappspec.yml(required for CodeDeploy), and deployment scripts. discard-paths: yesflattens the file structure in the output zip.
Checkpoint Questions
- Where should the
buildspec.ymlfile be located by default in a source repository? - Which AWS service is specifically designed to share private software packages across an organization using standard package managers like npm or pip?
- How can you ensure that Docker images stored in ECR do not contain known vulnerabilities before deployment?
- What is the benefit of using EC2 Image Builder over manual AMI creation?
[!TIP] Answers: 1. Root directory. 2. AWS CodeArtifact. 3. Enable "Scan on push" in ECR or use Amazon Inspector. 4. Automation of patching, testing, and multi-region distribution.
Muddy Points & Cross-Refs
- S3 vs. CodeArtifact: Use S3 for deployment bundles (zips) intended for CodeDeploy or Lambda. Use CodeArtifact for code dependencies (libraries) used during the
buildphase by developers or build servers. - Secondary Artifacts: A single CodeBuild project can produce multiple artifact sets. These are defined as named blocks in the
artifactssection and are useful for multi-stage pipelines. - Cross-Account Access: To allow a Production account to pull an image from a Dev account's ECR, you must update the ECR Repository Policy (Resource-based policy) to grant
ecr:BatchGetImageandecr:GetDownloadUrlForLayerto the Prod IAM role.
Comparison Tables
| Feature | Amazon S3 | Amazon ECR | AWS CodeArtifact |
|---|---|---|---|
| Primary Use | General objects / Deployment zips | Container Images (Docker/OCI) | Language Packages (npm/mvn) |
| Versioning | Optional (Bucket Versioning) | Native (Image Tags) | Native (Package Versions) |
| Access Control | IAM / Bucket Policies | IAM / Repository Policies | IAM / Domain Policies |
| Lifecycle | Lifecycle Rules (Transition/Expire) | Lifecycle Policies (Tag-based) | Manual / CLI cleanup |
| Integration | CodeDeploy / Lambda / CloudFront | ECS / EKS / App Runner | CodeBuild / Local Dev Machines |