Cloud concept · Updated

Dependency Pinning - Dependency pinning fixes build dependencies to explicitly selected versions or immutable identifiers so automated builds do not silently consume different inputs.

In short

Dependency pinning replaces floating dependency selections with controlled references recorded in manifests, lockfiles, or build configuration. It improves artifact consistency, troubleshooting, and rollback, but requires deliberate updates to incorporate security fixes and compatibility changes.

Cloud Concepts Hub →

5 key aspects of Dependency Pinning

Dependency pinning combines explicit versions, transitive dependency control, integrity verification, and reviewed updates to make artifact generation more predictable.

01
Explicit dependency selection

Replace floating versions, broad constraints, and moving references with selected versions or immutable identifiers. Apply this to libraries and build tooling, not just application runtime dependencies.

02
Transitive dependency control

Use ecosystem-appropriate lockfiles or fully resolved dependency specifications to capture indirect dependencies. Configure CI to reject inconsistent manifests and lockfiles rather than re-resolving them during release builds.

03
Content identity and integrity

Use container image digests and package hashes where supported to identify or validate the expected bytes. Exact version labels are useful, but their immutability depends on the repository's publishing controls.

04
Controlled artifact generation

Keep dependency specifications and build instructions under version control, and retain dependency metadata with generated artifacts. Promote the same tested artifact between environments instead of independently rebuilding each deployment.

05
Deliberate dependency maintenance

Update pinned dependencies through reviewed changes with automated testing and security checks. Pinning prevents unexpected changes, but leaving pins unchanged indefinitely can retain known vulnerabilities.

Cloud services for Dependency Pinning

CodePipeline can orchestrate a release in which CodeBuild installs locked dependencies from CodeArtifact and generates an application artifact. For container workloads, CodeBuild can push the resulting image to Amazon ECR and record its digest for subsequent deployment stages. The pipeline should promote the same tested artifact, while repository permissions and retention policies protect the required inputs and outputs. These services support the workflow, but dependency manifests, lockfiles, integrity checks, and build commands must explicitly enforce pinning.

AWS CodeBuildAWS CodeBuild

CodeBuild runs the installation and build commands that enforce pinned dependencies, such as npm ci or hash-checked Python installations. Version-controlled build specifications should also control build tools and avoid silently refreshing dependency selections.

AWS CodeArtifactAWS CodeArtifact

CodeArtifact provides managed package repositories from which builds can retrieve selected dependency versions. Repository permissions and package origin controls complement pinning by controlling publishing and upstream ingestion, but package-manager configuration still determines which versions the build selects.

AWS CodePipelineAWS CodePipeline

CodePipeline orchestrates source, build, test, approval, and deployment stages around controlled artifact generation. Design the pipeline to pass the generated artifact or its immutable reference downstream rather than rebuilding with potentially changed dependencies.

Dependency Pinning exam questions

Real practice exam questions on Dependency Pinning, with the correct answer and its explanation. Answer them with every option in the exam simulator.

DVA-C02

A team uses AWS Amplify Hosting to deploy a Node.js frontend from a release-approved Git branch for integration testing. The build runs npm install. The repository contains package.json with version ranges but does not contain package-lock.json. Clean builds of the same approved commit have started producing different test results after indirect npm dependencies released updates. The Node.js and npm versions are already fixed in the build environment.

The team must make each build use the complete dependency selection reviewed for that release. Builds must fail if dependency declarations are inconsistent with that selection. Dependency updates must remain possible through reviewed source changes.

Which solution meets these requirements?

Show answerCORRECT ANSWER

Generate and review package-lock.json, commit it alongside package.json, and configure the Amplify build to run npm ci. Submit changes to both files for review when updating dependencies.

The committed lockfile records the resolved direct and indirect dependency graph. npm ci installs from that lockfile without updating dependency selections and fails if package.json and the lockfile disagree. Reviewed changes to the files provide a controlled update process.

DOP-C02

A company uses AWS CodeBuild to generate deployment packages for a Node.js application. Rebuilding an older release from the same source commit recently introduced a regression because an indirect npm dependency had changed. The build runs npm install, and the repository contains package.json with version ranges but does not contain package-lock.json. The Node.js and npm versions and the build container image digest are already fixed.

The company requires each release commit to select the same direct and indirect dependency versions on fresh build workers. Security updates must be introduced through reviewed source changes rather than automatically during release builds. The package registry retains all required package versions.

Which change should a DevOps engineer implement?

Show answerCORRECT ANSWER

Generate and commit package-lock.json alongside package.json, and run npm ci in CodeBuild without regenerating the lockfile. Introduce dependency updates through reviewed changes to the dependency files.

The committed lockfile records the resolved direct and indirect dependency graph. npm ci installs from that lockfile without updating it and fails if it disagrees with package.json. Reviewed dependency-file changes allow deliberate security updates while keeping release builds on the recorded selections.

Practice Dependency Pinning in a full exam

Questions on Dependency Pinning in each practice exam, with every answer option and an explanation for each:

Start a free practice exam

What is Dependency Pinning

2 min read

Dependency pinning controls which external components are used when generating a software artifact. Instead of resolving whichever release currently satisfies a broad constraint, the build uses explicitly selected dependency versions or immutable content identifiers. Dependencies include application libraries, container base images, compiler toolchains, build plugins, and operating-system packages. In cloud CI/CD pipelines, this reduces situations where unchanged source code produces a different application because an upstream component changed.

A dependency manifest and a lockfile serve different purposes. A manifest can describe acceptable versions, while a lockfile records the resolved dependency graph, including indirect dependencies where the package manager supports it. Pinning only a top-level library is insufficient if that library's transitive dependencies can still resolve differently. Commit the relevant lockfile alongside the source code and configure CI to install from it without silently updating dependency selections.

For example, a Node.js build can run npm ci against a committed package-lock.json. This command requires the manifest and lockfile to agree and does not rewrite them during installation. A Python workflow can install a fully pinned requirements file with pip's --require-hashes option, provided all required dependencies are explicitly listed and have acceptable hashes. Hash validation adds content-integrity checking; a version number alone does not prove that downloaded bytes match a previously approved package.

Container builds require similar discipline. A base-image reference such as python:3.12 can move to a newer image, even though the Dockerfile remains unchanged. Referencing an image by digest fixes its content identity. However, a Dockerfile that subsequently installs unpinned packages from a changing operating-system repository can still produce different results. Build-image versions, package repository availability, target architecture, and downloaded build tools also affect the resulting artifact.

In a cloud build service, dependency installation belongs in version-controlled build instructions. Fetch dependencies from controlled repositories, verify available integrity metadata, and fail the build when locked dependencies cannot be obtained rather than silently substituting newer versions. Record the source revision and dependency metadata with the generated artifact. Build the release artifact once, then promote that same artifact through testing and production instead of rebuilding separately for each environment.

Pinning is not equivalent to caching, vulnerability scanning, or complete reproducibility. A cache accelerates downloads but does not define the required versions, and pinned packages can still contain vulnerabilities. Byte-for-byte reproducibility also requires control over timestamps, compiler behavior, and other environmental inputs. Manage the maintenance trade-off through reviewed dependency-update changes, automated tests, vulnerability checks, and an emergency patch process. For artifact-generation questions, distinguish controlled build inputs from merely storing build outputs: both matter, but artifact storage alone cannot prevent dependency drift.

Learn Dependency Pinning in lessons

2 short lessons on Dependency Pinning in 1 certification course.

Open the lessons