Skip to main content
Welcome. This lesson explains artifact lifecycle, secure storage patterns for code, and how to use AWS services to store, scan, and retain artifacts produced by CI/CD pipelines.

What is an artifact?

An artifact is a built, compiled, or packaged piece of software produced by a CI/CD workflow. It captures a reproducible, versioned snapshot of a software component that you can publish and distribute. Common artifact examples include:
  • Application packages (ZIP, JAR, WAR)
  • Container images and container layers
  • Infrastructure-as-code outputs (CloudFormation templates, CDK synthesized artifacts)
  • Helm charts, YAML/JSON manifests, AMIs (Amazon Machine Images), golden images
  • Third-party libraries or internally built dependencies
Versioning is critical. Store source in a source control system (Git) and store built outputs in an artifact repository so you can reproduce and trace releases. A release is a collection of versioned artifacts that together form a delivery unit (for example, version 1.0).
A slide titled "What Is an Artifact?" showing three categories: Source Code Artifacts (ZIP, JAR, WAR), Container Artifacts (Docker images, container layers), and Infrastructure as Code Artifacts (CloudFormation templates, CDK outputs). The slide is branded © Copyright KodeKloud.
Artifact types are broad and often reusable: container layers can be cached and reused across images; Helm charts or JSON manifests can be stored and referenced; any file format can be treated as an artifact if you need reproducibility and traceability.

AWS services for storing artifacts

AWS provides first-party services optimized for different artifact types:
  • AWS CodeArtifact — Managed package repository for Maven, npm, PyPI, NuGet. Ideal for internal libraries and proxied third-party packages; integrates with IAM for access control.
  • Amazon S3 — General-purpose object store suitable for build artifacts, ZIPs, binaries, serverless deployments and IaC artifacts. Supports bucket versioning and lifecycle policies for retention and cost optimization.
  • Amazon ECR (Elastic Container Registry) — Purpose-built registry for OCI/Docker images and layers. Provides image storage, IAM-based access, lifecycle policies, and image scanning features.
An infographic titled "Artifacts in Different AWS Services" that lists AWS CodeArtifact and Amazon S3 with icons and use cases. It highlights S3 as storage for build artifacts, supporting versioning and lifecycle policies and being ideal for serverless deployments.

Image scanning and image consumption notes

  • ECR supports vulnerability scanning on push and can integrate with third-party scanners like Trivy. For deeper scanning and runtime checks, integrate Amazon Inspector or other security tools.
  • Container images stored in ECR can be consumed across AWS services: Lambda (container images as functions), ECS/EKS (task definitions and pods), and EC2.
  • CodeArtifact is less feature-rich than some enterprise products (e.g., JFrog Artifactory), but it offers native AWS integration and is sufficient for many teams.

Artifact flow in CI/CD pipelines

A typical AWS CI/CD pipeline flow:
  1. Source repo (CodeCommit, GitHub, etc.) triggers the pipeline.
  2. Build step (CodeBuild) executes install, pre_build, build, and post_build phases.
  3. Build outputs are pushed to one or more artifact stores (CodeArtifact, S3, ECR).
  4. Deployment stages pull artifacts from storage and deploy to targets (CodeDeploy, ECS, Lambda, EC2).
This flow centralizes artifact creation, scanning, storage, and distribution to ensure reproducibility and traceability.
A diagram titled "CodeBuild Artifact Generation Flow" showing AWS CodeCommit feeding source to AWS CodeBuild, which then uploads build artifacts. The artifacts are stored in AWS CodeArtifact, Amazon S3, and Amazon ECR.

Example: CodeBuild buildspec

Below is a minimal buildspec.yml that demonstrates CodeBuild phases and artifact publishing. Customize the commands and paths to match your project and artifact destinations.
You can push container images to ECR using the Docker CLI or AWS CLI from the post_build phase, upload compiled artifacts to S3, or publish packages to CodeArtifact.

Retention and lifecycle management

Retention strategies differ per service. Implement automated lifecycle rules to control storage costs and limit the blast radius of old or unscanned artifacts.
Slide titled "Retention and Clean Up Stages" showing three colored service icons. From left to right: S3 Lifecycle Policies (green bucket), ECR Lifecycle Policies (orange repository icon), and CodeArtifact Retention (purple code/artifact icon).

Best practices for artifact management

  • Immutable artifacts: treat published artifacts as immutable. If a release is incorrect, publish a new version rather than mutating an existing artifact.
  • Consistent environments: package dependencies and configuration so artifacts behave identically across staging and production.
  • Automate everything: artifact creation, scanning, storage, and distribution should be automated in CI/CD pipelines to reduce human error.
  • Metadata and provenance: publish metadata (release notes, dependency lists, SBOMs) alongside the artifact so consumers can verify provenance and contents.
  • Security and access control: restrict who can publish or delete artifacts using IAM, and enable audit logging to track changes.
  • Scanning and signing: enable image/package scanning and consider cryptographic signing and attestation to enforce trust boundaries.
A slide titled "Best Practices" showing four illustrated cards labeled "Immutable artifacts," "Consistent environments," "Automation," and "Documentation." Each card has a circular icon above it (document with a lock, document with a gear, a gear with a plug, and a plain document) with colored outlines.
Automate metadata collection (for example, a simple JSON or SBOM) and retention policies. If you must comply with supply-chain standards such as SLSA, include reproducible artifact creation and provenance tracking in your pipeline from day one.

Summary

Artifacts are versioned, reproducible snapshots of software used across environments. Select the right AWS service for the artifact type:
  • Use CodeArtifact for package repositories (Maven, npm, PyPI, NuGet).
  • Use S3 for general-purpose object storage and IaC artifacts.
  • Use ECR for OCI/Docker images and container layers.
Automate creation, scanning, storage, retention, and documentation to ensure artifacts remain traceable and trustworthy. Practical labs and demos demonstrating these patterns are available.

Watch Video