This workspace demonstrates AWS CodeArtifact capabilities with two CDK projects deployed via separate CodePipeline environments.
graph TB
subgraph GitHub["GitHub Repository"]
SharedLib["shared-library/"]
ConsumerApp["consumer-app/"]
end
subgraph CodeArtifact["AWS CodeArtifact Domain"]
NpmUpstream["npm-upstream<br/>(public:npmjs)"]
PrivateRepo["private-packages<br/>(@my-company/shared-utils)"]
NpmUpstream -->|upstream| PrivateRepo
end
subgraph SharedPipeline["Shared Library Pipeline"]
SrcStage1["Source<br/>(GitHub)"]
BuildStage1["Build & Test<br/>(CodeBuild)"]
PublishStage1["Publish<br/>(npm publish)"]
SrcStage1 --> BuildStage1
BuildStage1 --> PublishStage1
end
subgraph ConsumerPipeline["Consumer App Pipeline"]
SrcStage2["Source<br/>(GitHub)"]
BuildStage2["Build & Test<br/>(CodeBuild)"]
DeployStage2["Deploy<br/>(CDK)"]
SrcStage2 --> BuildStage2
BuildStage2 --> DeployStage2
end
subgraph AppStack["Deployed Application"]
Lambda["Lambda Function<br/>(Node.js 20)"]
end
SharedLib -->|triggers on<br/>shared-library/**| SrcStage1
ConsumerApp -->|triggers on<br/>consumer-app/**| SrcStage2
BuildStage1 -->|npm install| PrivateRepo
PublishStage1 -->|npm publish| PrivateRepo
BuildStage2 -->|npm install| PrivateRepo
DeployStage2 -->|npm install| PrivateRepo
DeployStage2 -->|deploys| Lambda
Lambda -.->|uses| PrivateRepo
style CodeArtifact fill:#FF9900,stroke:#232F3E,stroke-width:3px,color:#fff
style SharedPipeline fill:#3F8624,stroke:#232F3E,stroke-width:2px,color:#fff
style ConsumerPipeline fill:#3F8624,stroke:#232F3E,stroke-width:2px,color:#fff
style AppStack fill:#527FFF,stroke:#232F3E,stroke-width:2px,color:#fff
style GitHub fill:#24292e,stroke:#232F3E,stroke-width:2px,color:#fff
- codeartifact-infra/ - CDK infrastructure for CodeArtifact domain and repositories
- shared-library/ - Reusable npm package published to CodeArtifact
- consumer-app/ - CDK application consuming the shared library from CodeArtifact
- AWS CLI configured with appropriate credentials
- Node.js 18+ and npm
- AWS CDK CLI (
npm install -g aws-cdk)
-
Deploy CodeArtifact infrastructure first:
cd codeartifact-infra npm install cdk deploy -
Build and publish the shared library:
cd shared-library npm install cdk deploy SharedLibraryPipelineStack -
Deploy the consumer application:
cd consumer-app npm install cdk deploy ConsumerAppPipelineStack
- Private npm package publishing
- Upstream repository configuration (npm public registry)
- Pipeline authentication with CodeArtifact
- Cross-project package consumption
- IAM-based access control
my-company-domain
├── npm-upstream (external connection to public:npmjs)
│ └── Caches: aws-cdk-lib, constructs, typescript, etc.
└── private-packages (upstream: npm-upstream)
└── Contains: @my-company/shared-utils
└── Proxies: all public packages from npm-upstream
sequenceDiagram
participant NPM as npmjs.org
participant CA as CodeArtifact<br/>(private-packages)
participant SP as Shared Library<br/>Pipeline
participant CP as Consumer App<br/>Pipeline
participant Lambda as Lambda Function
Note over SP: Build Stage
SP->>CA: npm install (dev dependencies)
CA->>NPM: Fetch public packages (if not cached)
NPM-->>CA: typescript, aws-cdk, etc.
CA-->>SP: Return packages
Note over SP: Publish Stage
SP->>CA: npm publish @my-company/shared-utils@1.0.0-abc1234
CA-->>SP: Package published
Note over CP: Build Stage
CP->>CA: npm install
CA-->>CP: @my-company/shared-utils + public packages
Note over CP: Deploy Stage
CP->>CA: npm install (for CDK deploy)
CA-->>CP: All dependencies
CP->>Lambda: Deploy with bundled dependencies
Note over Lambda: Runtime
Lambda->>Lambda: Uses @my-company/shared-utils<br/>from bundle
All npm packages flow through CodeArtifact - demonstrating a single source for both private and public packages:
- Pre-build: Authenticates with CodeArtifact using
aws codeartifact login - Build:
npm installpulls dev dependencies (typescript, aws-cdk, etc.) from CodeArtifact- Public packages are cached from npm-upstream
- Private packages come from private-packages repository
- Post-build:
npm publishpushes@my-company/shared-utilsto CodeArtifact
- Pre-build: Authenticates with CodeArtifact
- Build:
npm installpulls:@my-company/shared-utilsfrom private-packages- Public packages (aws-cdk-lib, constructs) from npm-upstream via private-packages
- Pre-build:
- Authenticates with CodeArtifact
- Copies
.npmrcfor Docker bundling npm install -g aws-cdk- gets CDK from CodeArtifact
- Build: CDK deploy bundles Lambda with dependencies from CodeArtifact
✅ Single Source of Truth - All packages (public and private) come from CodeArtifact ✅ Caching - Public npm packages are cached, reducing external dependencies ✅ Access Control - IAM-based authentication for all package operations ✅ Versioning - Automatic versioning based on git commit hash ✅ Audit Trail - All package downloads and publishes are logged