Skip to content

vdanniel/codeartifact-poc

Repository files navigation

AWS CodeArtifact PoC

This workspace demonstrates AWS CodeArtifact capabilities with two CDK projects deployed via separate CodePipeline environments.

Architecture Diagram

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
Loading

Project Structure

  • 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

Prerequisites

  • AWS CLI configured with appropriate credentials
  • Node.js 18+ and npm
  • AWS CDK CLI (npm install -g aws-cdk)

Setup Steps

  1. Deploy CodeArtifact infrastructure first:

    cd codeartifact-infra
    npm install
    cdk deploy
  2. Build and publish the shared library:

    cd shared-library
    npm install
    cdk deploy SharedLibraryPipelineStack
  3. Deploy the consumer application:

    cd consumer-app
    npm install
    cdk deploy ConsumerAppPipelineStack

CodeArtifact Features Demonstrated

  • Private npm package publishing
  • Upstream repository configuration (npm public registry)
  • Pipeline authentication with CodeArtifact
  • Cross-project package consumption
  • IAM-based access control

How CodeArtifact Works in This PoC

Repository Structure

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

Package Flow Diagram

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
Loading

Package Flow Across All Build Stages

All npm packages flow through CodeArtifact - demonstrating a single source for both private and public packages:

1. SharedLibrary Pipeline (Build & Publish)

  • Pre-build: Authenticates with CodeArtifact using aws codeartifact login
  • Build: npm install pulls 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 publish pushes @my-company/shared-utils to CodeArtifact

2. ConsumerApp Pipeline - Build Stage

  • Pre-build: Authenticates with CodeArtifact
  • Build: npm install pulls:
    • @my-company/shared-utils from private-packages
    • Public packages (aws-cdk-lib, constructs) from npm-upstream via private-packages

3. ConsumerApp Pipeline - Deploy Stage

  • Pre-build:
    • Authenticates with CodeArtifact
    • Copies .npmrc for Docker bundling
    • npm install -g aws-cdk - gets CDK from CodeArtifact
  • Build: CDK deploy bundles Lambda with dependencies from CodeArtifact

Key Benefits Demonstrated

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors