CodeArtifact package repositories
CodeArtifact provides an AWS-compatible package service for domains, repositories, package metadata, and package bytes. It combines a JSON management API with native Maven, npm, PyPI, NuGet, and Cargo registry endpoints. It also controls package sources, origin rules, tags, policies, and short-lived client access.
Resource model
Domains and repositories
A domain is the top-level boundary for related package repositories. A repository is a named package store inside a domain. Packages and their versions belong to a repository, while policies and tags belong to a domain or repository resource.
Repositories have separate internal storage identities for each package format. This keeps a new repository with the same name separate from a deleted repository and its old package content.
flowchart TD
A[Account and region] --> D[Domain]
D --> R1[Repository]
D --> R2[Repository]
R1 --> S[Source rules]
R1 --> P[Package metadata and assets]
D --> G[Package groups]
D --> T[Domain tags]
R1 --> RT[Repository tags]
References: src/…/CodeArtifactService.java• L426-449 src/…/CodeArtifactService.java• L530-570 src/…/CodeArtifactService.java• L700-715
Domain and repository lifecycle
Domain creation records ownership, region, encryption, time, and tags. A new domain is Active. The service limits an account to ten domains in a region. A domain cannot be deleted while it contains repositories.
Repository creation requires an existing domain. It records source choices, tags, and a new storage identity for each format. Deletion removes the public record, releases native storage, and clears package metadata and related service records. A later repository with the same name starts empty.
References: src/…/CodeArtifactService.java• L426-487 src/…/CodeArtifactService.java• L530-710 src/…/CodeArtifactService.java• L720-805 src/…/CodeArtifactController.java• L74-114 src/…/CodeArtifactController.java• L174-242
Package metadata and origin
A package identifies a package in a repository. A package version identifies one release. An asset is a named file for that release. Generic package metadata is held by the service. Maven, npm, PyPI, NuGet, and Cargo metadata is read from the matching native registry and combined with service state such as status, revision, readme, and source origin.
Each retained version has one source claim. The claim records whether the version entered through a public external connection or a same-domain upstream repository. Deletion, disposal, and repository replacement fences stop a delayed source fetch from restoring removed content.
References: src/…/CodeArtifactService.java• L2892-2927 src/…/RetentionOriginKind.java• L3-15 src/…/CodeArtifactService.java• L3514-3568 src/…/CodeArtifactService.java• L3824-3862
Package origin controls
Package origin controls decide whether a package accepts direct publishing and upstream retention. A package with no explicit record defaults to publish=ALLOW and upstream=BLOCK. The first successful retention from a source changes the default to publish=BLOCK and upstream=ALLOW, unless an explicit setting already exists.
Direct publishing and source retention both apply the package rule and the matching package-group rule. A blocked rule is checked before an idempotent retry, so identical bytes do not bypass an origin restriction.
References: src/…/CodeArtifactService.java• L2555-2611 src/…/CodeArtifactService.java• L3281-3356 src/…/CodeArtifactController.java• L369-387
Package groups
A package group is a domain-wide pattern that applies origin rules to matching format, namespace, and package coordinates. The root group /* supplies the base policy. More specific groups inherit from their nearest parent and can set rules for direct publishing, external sources, or internal upstreams.
Patterns support exact, word-boundary prefix, and wildcard matches. A weak match is blocked for publishing and retention. A group can allow all repositories, block them, inherit its parent, or allow only named repositories for one restriction type.
References: src/…/PackageGroupPatterns.java• L7-25 src/…/PackageGroup.java• L9-30 src/…/PackageGroupRestriction.java• L9-17 src/…/CodeArtifactService.java• L5498-5605
Package source resolution
Upstream repositories
An upstream is another repository in the same domain. The service searches the upstream graph in listed order and walks each branch before moving to the next branch. It keeps the first eligible local version found, and can use an upstream's own external connection as the last step in the search.
The request keeps the selected upstream storage in use until the version is copied. Archived or disposed versions are treated as unavailable, so the search can continue to a later candidate. A repository cannot combine upstreams with an external connection.
References: src/…/UpstreamRepositoryResolver.java• L12-27 src/…/UpstreamRepositoryResolver.java• L43-69 src/…/UpstreamExternalConnectionFetch.java• L8-20 src/…/CodeArtifactMavenUpstreamRepositoryImporter.java• L18-55 src/…/CodeArtifactCargoUpstreamRepositoryImporter.java• L21-67
External connections
An external connection names one public package source for a repository. A repository has at most one connection, and it cannot have upstream repositories at the same time. Public content is normally advertised first and retained only when a client requests the asset.
The supported public sources include Maven Central and other Maven registries, npm, PyPI, NuGet, RubyGems, Swift, and crates.io. A retained version keeps the source that supplied it, which prevents a later source change from creating a mixed version. Public-source reads use the registry's discovery response first, then fetch the exact asset only when the client requests it. A failed or unavailable public read behaves like a package miss.
References: src/…/CodeArtifactService.java• L70-92 src/…/CodeArtifactService.java• L989-1031 src/…/RetentionOriginKind.java• L3-15 src/…/NpmExternalConnectionClient.java• L22-51 src/…/NpmExternalConnectionClient.java• L119-223
Format retention rules
Each package protocol needs a different form of source discovery. The service keeps the same source and lifecycle rules across formats while matching the way each client finds an artifact.
| Format | Source discovery and retention behavior |
|---|---|
| Maven | Release metadata can be merged so ranges and dynamic versions resolve. A requested release then retains its artifact files. Snapshots are not retained from a public external connection. |
| npm | A packument can advertise public versions and tags. The requested tarball is retained later from its exact package and version path. Local package fields and tags are not replaced by public values. |
| PyPI | The simple index can advertise public files and preserves yanked and requires-python markers. The requested file is retained first, with other files for the same release retained in the background. File links always point to the CodeArtifact endpoint. |
| NuGet | Retention requires an exact package version. It does not discover a floating version from the public index. |
| Cargo | The sparse index is merged so Cargo can resolve a crate version. The .crate asset is retained only when Cargo requests the download. |
Public source failures and missing assets behave as ordinary package misses. Asset size and hash checks apply before a retained file is stored.
References: src/…/CodeArtifactMavenExternalConnectionImporter.java• L17-65 src/…/CodeArtifactNpmExternalConnectionImporter.java• L20-50 src/…/CodeArtifactPypiExternalConnectionImporter.java• L28-71 src/…/CodeArtifactNuGetExternalConnectionImporter.java• L16-49 src/…/CodeArtifactCargoExternalConnectionImporter.java• L27-53 src/…/CargoExternalConnectionClient.java• L81-88
Package registry endpoints
Endpoint discovery and authorization
Endpoint discovery returns a public URL for a selected package format. Package clients use that URL with a short-lived authorization token instead of sending a signed JSON API request. The token carries the domain account and region scope and is checked before native access.
The token extractor accepts the forms used by real clients: Bearer for npm, Basic with the token as the password for Maven, PyPI, and NuGet, and a bare token for Cargo. See IAM and auth for common access rules. The separation between signed management requests and native registry traffic is part of the request model described in request routing and protocols.
References: src/…/CodeArtifactService.java• L929-941 src/…/CodeArtifactController.java• L117-129 src/…/CodeArtifactService.java• L3827-3864 src/…/CodeArtifactTokenExtractor.java• L8-16
Native registry protocols
Native endpoints keep package-manager wire behavior separate from the JSON management API. They authenticate at the CodeArtifact route, check package status and source rules, and then serve or write content in the selected registry format.
| Format | Endpoint behavior |
|---|---|
| Maven | Serves standard group, artifact, version paths and metadata with GET, HEAD, and PUT. |
| npm | Proxies packuments, scoped packages, tarballs, publishing, and package unpublishing. |
| PyPI | Serves project simple indexes and package files for pip and uploads for twine. Public links point back to the CodeArtifact endpoint. |
| NuGet | Authors a V3 service index and serves package content and push. Restore works without search or registration resources. |
| Cargo | Authors config.json, sparse index files, crate downloads, and the Cargo publish route. |
flowchart LR
C[Package client] --> E[Discovered endpoint]
E --> T[Authorization token]
C --> P[Native registry request]
P --> V[Token, source, and status checks]
V --> B[Format backend]
B --> A[Package asset or metadata]
References: src/…/CodeArtifactController.java• L245-257 src/…/CodeArtifactMavenController.java• L28-46 src/…/CodeArtifactNpmDataPlane.java• L48-60 src/…/CodeArtifactPypiController.java• L45-60 src/…/CodeArtifactNuGetController.java• L37-68 src/…/CodeArtifactCargoController.java• L32-59
Maven artifact access
The Maven endpoint is the main artifact path for Maven and Gradle clients. It maps a GAV path to a package coordinate, checks direct-publish and version status rules, and keeps Maven metadata separate from a version's artifact files.
On a GET or HEAD miss, the endpoint tries the configured external connection or upstream chain. A public release can add its standard POM, JAR, sources, and javadoc assets together. A metadata request can add release versions without fetching all release bytes. Direct publishing of a release already present in the external source is rejected.
References: src/…/CodeArtifactMavenController.java• L64-151 src/…/CodeArtifactMavenController.java• L229-305 src/…/CodeArtifactMavenExternalConnectionImporter.java• L90-122 src/…/ReposiliteSidecarClient.java• L765-844
npm, PyPI, and NuGet access
npm, PyPI, and NuGet use native endpoints that adapt their metadata and asset rules to CodeArtifact. Each endpoint keeps public URLs in the CodeArtifact route and keeps sidecar addresses private.
PyPI project indexes merge local files with files advertised by an external connection or upstream. The endpoint rewrites file links to the public CodeArtifact route and preserves PyPI markers that affect client selection. A file miss can retain the requested file before it is streamed. Uploads check the filename-derived package identity, origin rule, version status, size, and existing bytes. An identical retry succeeds while different bytes conflict. This keeps the sidecar's flat file store aligned with CodeArtifact package metadata even when a client omits or misstates upload fields.
Downloads and publishes apply package origin controls and Archived or Disposed status before an idempotent retry. Native package stores remain the source of truth for package-manager content. The JSON API reads those stores through the common sidecar contract.
References: src/…/CodeArtifactNpmDataPlane.java• L112-247 src/…/CodeArtifactPypiController.java• L116-173 src/…/CodeArtifactPypiController.java• L247-289 src/…/CodeArtifactPypiController.java• L307-499 src/…/CodeArtifactPypiController.java• L731-749 src/…/PypiserverSidecarClient.java• L89-165 src/…/PypiserverSidecarClient.java• L435-521 src/…/CodeArtifactNuGetController.java• L131-217 src/…/RepositorySidecarManager.java• L15-27
Cargo access
The Cargo endpoint supports the registry features needed for dependency resolution, crate download, and publish. It returns one CodeArtifact endpoint in config.json, then serves the sparse index and crate files from the same route.
Cargo must see index entries before it can request a crate. The endpoint therefore merges eligible local, upstream, and crates.io index lines. A missing crate download can then retain the exact crate and its checksum before streaming it to Cargo.
References: src/…/CodeArtifactCargoController.java• L32-59 src/…/CodeArtifactCargoController.java• L110-210 src/…/CodeArtifactCargoController.java• L226-318 src/…/KellnrSidecarClient.java• L36-73
Native storage backends
The public endpoints use a common sidecar contract for native package data. The contract covers readiness, leases, package and version lookup, asset streaming, enumeration, copy, deletion, and format-specific metadata. See storage backend for the wider storage model.
Maven uses one shared backend with a named repository for each CodeArtifact repository. npm, PyPI, NuGet, and Cargo use one backend per CodeArtifact repository. These backends are private to the emulator. Public handlers perform token and repository checks before they use them.
The sidecars start when a format is first used and stop after repository deletion, reset, or shutdown. Their package bytes are not durable across an emulator restart, so service metadata and native content can have different lifetimes.
Each repository format has a lease. A lease keeps its sidecar alive through an in-flight request or streamed response. Repository deletion marks the sidecar for release but waits for active uses to finish before stopping it.
References: src/…/RepositorySidecarManager.java• L30-53 src/…/RepositorySidecarManager.java• L112-150 src/…/SidecarRepositoryLease.java• L9-130 src/…/CodeArtifactContainerRuns.java• L13-29 src/…/ReposiliteSidecarManager.java• L22-31 src/…/VerdaccioSidecarManager.java• L89-163 src/…/PypiserverSidecarManager.java• L59-151 src/…/BagetterSidecarManager.java• L67-155 src/…/KellnrSidecarManager.java• L83-211
Resource governance
Resource policies and tags
Resource policies hold access rules for a domain or repository. The API supports one policy per resource with revision checks, so a stale write does not replace a newer policy.
Tags are key-value labels on domains, repositories, and package groups. Tag actions use the resource ARN and can add, replace, remove, or list tags. Tag keys cannot use the aws: prefix and a resource can have up to 200 tags.
References: src/…/CodeArtifactService.java• L943-987 src/…/CodeArtifactService.java• L3882-3909 src/…/CodeArtifactController.java• L851-874
Native storage lifecycle
Native stores are created on first use and kept in use while a request reads or writes them. Repository deletion waits for active format requests before releasing storage. This protects streamed downloads and source copies from a concurrent repository delete.
Large assets are streamed or staged rather than held in memory. The same lifecycle boundary covers direct publish, copy, source retention, package deletion, and status disposal.
References: src/…/CodeArtifactService.java• L720-823 src/…/CodeArtifactService.java• L832-871 src/…/RepositorySidecarManager.java• L359-373 src/…/CodeArtifactNuGetController.java• L160-173
JSON API
Management surface
The CodeArtifact API accepts AWS-style JSON requests and returns JSON resource views. Generic package publishing is the main binary exception because its body is the asset content. The request region comes from the request context, while domain owners and ARNs select account scope where needed.
The management actions cover these areas:
| Area | Capabilities |
|---|---|
| Domains | Create, describe, list, delete, and policy management |
| Repositories | Create, describe, update, list, delete, endpoint discovery, source configuration, and policy management |
| Packages | Describe, list, origin controls, and delete |
| Package versions | Publish, describe, list, asset reads, dependency reads, copy, status changes, disposal, deletion, readmes, and origin views |
| Package groups | Create, describe, update, list, hierarchy, origin rules, allowed repositories, and package association |
| Tags | Tag, untag, and list resource tags |
| Access | Authorization tokens and revision-checked resource policies |
Routes use CodeArtifact-style /v1 paths. Lists use continuation tokens. Native package handlers serve the separate URLs returned by endpoint discovery.
References: src/…/CodeArtifactController.java• L74-317 src/…/CodeArtifactController.java• L319-716 src/…/CodeArtifactController.java• L717-850
Package version views
The JSON API presents a single view across generic metadata and native registry content. It reports package and version status, revisions, origin, assets, readmes, and dependencies even when the bytes live in a format-specific backend.
Maven dependencies come from the POM. npm dependencies come from the version document. PyPI dependencies come from wheel or source-distribution metadata. NuGet dependencies come from the .nuspec. The API also supports package-version copy across the supported formats, with optional upstream lookup and all-or-nothing batch behavior.
References: src/…/RepositorySidecarManager.java• L165-213 src/…/PomDependencies.java• L13-34 src/…/PypiVersionMetadata.java• L17-24 src/…/NuspecXml.java• L45-58 src/…/CodeArtifactService.java• L4390-4450
Validation and lifecycle errors
The API reports malformed input, missing resources, conflicts, and quota limits as AWS-style errors. These results distinguish an invalid request from a missing resource and from a valid request that conflicts with current source or version state.
Important rules include:
- A repository requires an existing domain.
- A domain with repositories cannot be deleted.
- A repository cannot combine upstreams with an external connection.
- A package group or package rule can block direct publish or source retention.
- Archived and disposed versions cannot be republished, copied over, or downloaded through native package paths.
- Native package access requires a live token and a ready backend.
- Generic assets must match their supplied hash and size limits.
- Maven public retention is release-only and direct republish of a retained release is rejected.
- NuGet retention needs an exact version. Cargo and npm need their index or metadata discovery step.
- PyPI file names must identify the claimed package and version.
- A stale policy revision is rejected.
References: src/…/CodeArtifactService.java• L2555-2679 src/…/CodeArtifactService.java• L3281-3356 src/…/CodeArtifactController.java• L1270-1279
Change checklist
When these files or sections are changed, remember to consider these:
- Keep domain ownership and repository identity aligned across create, list, describe, endpoint, source, and delete actions.
- Keep repository deletion aligned with native backend release and cleanup of generic assets, status overrides, readmes, origin claims, and byte totals.
- Keep upstream and external-connection exclusivity aligned across create, update, associate, and disassociate actions.
- Keep upstream search order, cycle checks, source claims, and Archived or Disposed filtering aligned across all five package formats.
- Keep each format's discovery contract aligned with its retention trigger: Maven metadata, npm packuments, PyPI indexes, NuGet exact versions, and Cargo sparse indexes.
- Keep PyPI filename-derived coordinates aligned with upload fields, status guards, byte comparison, and public index links.
- Keep npm packument discovery aligned with exact tarball paths and the rule that external fetch failures are package misses.
- Keep public package links pointed at the CodeArtifact endpoint and never at a sidecar address.
- Keep package-group pattern strength, parent selection, inherited modes, and allowed-repository lists aligned with direct publish and both upstream restrictions.
- Keep native token scope checks aligned across Bearer, Basic, and bare-token request forms.
- Keep native leases active through streamed responses and upstream copies before backend release.
- Keep sidecar container labels and the shared CodeArtifact run identity aligned so reset and cleanup find every format backend.
- Keep package metadata, native assets, status records, readmes, dependencies, revisions, and origin views consistent after publish, copy, retention, disposal, and delete.
- Keep tag ARN parsing, lowercase tag fields, policy revisions, pagination tokens, and JSON response names aligned with the AWS wire contract.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| Delete a domain that still has repositories | The domain remains and the API returns a conflict | Delete repositories first |
| Add upstreams to a repository with an external connection | The source change is rejected | Remove the external connection first |
| Use an expired or wrong-domain token | Native package access is unauthorized | Request a token for the endpoint domain |
| Retain a version after its package or repository was deleted | Removed content can be restored | Use source claims and deletion fences before every retained write |
| Resolve a package through an Archived or Disposed upstream version | The candidate is unavailable | Continue to the next eligible upstream |
| Use a weak package-group match | Publish or source retention is blocked | Use a strong matching package-group pattern |
| Request a Maven snapshot through a public external connection | The request remains a normal miss | Publish the snapshot directly or use a same-domain upstream |
| Request a NuGet version without an exact version | External retention does not discover it | Request a fixed package version |
| Request a Cargo crate before its sparse index is available | Cargo cannot resolve the crate | Serve the merged sparse index and then retain the crate |
| Let a PyPI index expose an internal backend link | pip follows an unreachable URL | Rewrite links to the public CodeArtifact endpoint |
| Publish different bytes for an existing PyPI file | The publish conflicts | Keep asset names immutable or delete before an explicit copy overwrite |
| Hold a native backend lease only until the handler returns | A streamed response can fail after repository cleanup | Release the lease when the response stream closes |
| Expose a sidecar beyond the emulator's private path | A caller can bypass CodeArtifact token and source checks | Bind sidecars to the private emulator path and keep authorization at the proxy |
| Restart the emulator while native sidecars hold package bytes | Native package content is lost while durable metadata can remain | Treat native sidecar content as restart-scoped state |
| Use a stale policy revision | A newer policy is not replaced | Read and supply the current revision |
| Let an npm external GET fail during discovery or tarball fetch | The package or version is treated as unavailable | Treat non-success responses and transport errors as misses |
| Stream a PyPI download without holding its sidecar lease | Repository cleanup can stop the backend before the client finishes | Release the lease only when the response stream closes |
Key files
| File | Why to read it |
|---|---|
| src/…/CodeArtifactController.java | Shows the AWS-compatible JSON routes for domains, repositories, packages, package groups, policies, tags, and tokens. |
| src/…/CodeArtifactService.java | Defines resource lifecycle, origin controls, source resolution, status rules, endpoint discovery, tokens, cleanup, and package-group policy behavior. |
| src/…/CodeArtifactMavenController.java | Shows Maven artifact paths, metadata access, token checks, publishing, and source-retention triggers. |
| src/…/CodeArtifactMavenExternalConnectionImporter.java | Shows public Maven release retention and metadata discovery. |
| src/…/CodeArtifactMavenUpstreamRepositoryImporter.java | Shows priority-ordered and transitive Maven upstream lookup. |
| src/…/CodeArtifactNpmDataPlane.java | Shows npm registry proxying, publish checks, packument responses, tarball retention, and unpublishing. |
| src/…/NpmExternalConnectionClient.java | Shows npm public-source discovery, exact tarball access, bounded asset transfer, and miss handling. |
| src/…/CodeArtifactPypiController.java | Shows PyPI indexes, public-link rewriting, lazy file retention, upload checks, and streamed responses. |
| src/…/CodeArtifactNuGetController.java | Shows the NuGet V3 service index, package reads, push, exact-version retention, and leases. |
| src/…/CodeArtifactCargoController.java | Shows Cargo configuration, sparse-index serving, crate download, and publish behavior. |
| src/…/CodeArtifactCargoExternalConnectionImporter.java | Shows crates.io index merging, checksum-aware crate retention, and source claims. |
| src/…/CodeArtifactCargoUpstreamRepositoryImporter.java | Shows Cargo upstream index merging and transitive source resolution. |
| src/…/PackageGroupPatterns.java | Defines package-group matching, weak matches, specificity, and hierarchy. |
| src/…/PackageGroup.java | Defines domain-wide package-group metadata and restriction state. |
| src/…/RepositorySidecarManager.java | Defines the common boundary between CodeArtifact metadata and native package stores. |
| src/…/SidecarRepositoryLease.java | Shows how repository deletion and in-flight native requests share sidecar lifetime. |
| src/…/CodeArtifactContainerRuns.java | Shows the shared identity used to find and clean up CodeArtifact sidecars. |
| src/…/VerdaccioSidecarManager.java | Shows the per-repository npm backend lifecycle. |
| src/…/PypiserverSidecarManager.java | Shows the per-repository PyPI backend lifecycle. |
| src/…/BagetterSidecarManager.java | Shows the per-repository NuGet backend lifecycle. |
| src/…/KellnrSidecarManager.java | Shows the per-repository Cargo backend lifecycle. |
| src/…/ReposiliteSidecarClient.java | Shows shared Maven repository storage, metadata, artifact access, and release. |
| src/…/VerdaccioSidecarClient.java | Shows npm package documents, tarballs, version data, and package deletion. |
| src/…/PypiserverSidecarClient.java | Shows PyPI package indexes, filename and version checks, normalization, asset access, streaming, and sidecar operations. |
| src/…/BagetterSidecarClient.java | Shows NuGet package assets, version normalization, readmes, and deletion. |
| src/…/KellnrSidecarClient.java | Shows Cargo sparse indexes, crate assets, publishing, and hard deletion. |
| src/…/CodeArtifactTokenExtractor.java | Defines the native client authorization forms. |