Skip to main content

intro

sdlcs-aws-cdk-lib

AWS CDK library with extended constructs, Blue-Green/Canary deployment patterns, and context-aware environment management.

npm version License: MIT

๐Ÿ“š Documentationโ€‹

Full Documentation โ†’

๐Ÿš€ Featuresโ€‹

  • Extended AWS CDK Constructs: Custom wrappers with automatic naming and tagging
  • Blue-Green Lambda Deployments: Zero-downtime deployments with automatic rollback
  • Context Strategy: Environment-aware configuration (dev, staging, prod, test, qa, preprod)
  • Package Metadata Integration: Automatic resource tagging from package.json
  • Canary Traffic Shifting: Gradual rollout with CodeDeploy integration
  • Type-Safe: Full TypeScript support with strict mode enabled

โšก Quick Startโ€‹

# Install
npm install sdlcs-aws-cdk-lib aws-cdk-lib constructs

# Use in your CDK app
import { App, Stack } from 'sdlcs-aws-cdk-lib';

const app = new App();
const stack = new Stack(app, 'MyStack');

// Deploy
cdk deploy --context stage=dev

See the Quick Start Guide for a complete example.

๐Ÿ“‹ Prerequisitesโ€‹

  • Node.js >= 22.0.0
  • npm >= 10.9.2
  • AWS CLI configured with appropriate credentials
  • AWS CDK v2.160.0 or later

๐Ÿ› ๏ธ Developmentโ€‹

# Clone and install
git clone https://github.com/akfdev-com/sdlcs-aws-cdk-lib.git
cd sdlcs-aws-cdk-lib
npm install

# Build
npm run build

# Run tests
npm test

# Lint
npm run lint

๐Ÿ“ฆ Project Structureโ€‹

sdlcs-aws-cdk-lib/
โ”œโ”€โ”€ bin/ # CDK app entry point
โ”œโ”€โ”€ lib/ # Example stacks
โ”‚ โ”œโ”€โ”€ SimpleStack.ts # Blue-Green Lambda example
โ”‚ โ”œโ”€โ”€ GithubOidcStack.ts # GitHub OIDC authentication
โ”‚ โ””โ”€โ”€ lambda/ # Construct definitions
โ”‚ โ””โ”€โ”€ BlueGreenLambda.ts
โ”œโ”€โ”€ src/ # Core library code
โ”‚ โ””โ”€โ”€ contextStrategy/ # Context management
โ”‚ โ”œโ”€โ”€ ContextStrategy.ts
โ”‚ โ””โ”€โ”€ PackageJsonDetails.ts
โ”œโ”€โ”€ src-extends-aws-cdk-lib/ # Extended CDK constructs
โ”‚ โ”œโ”€โ”€ App.ts # Extended App with ContextStrategy
โ”‚ โ”œโ”€โ”€ Stack.ts # Extended Stack with auto-naming
โ”‚ โ”œโ”€โ”€ aws-lambda/ # Lambda extensions
โ”‚ โ”œโ”€โ”€ aws-lambda-nodejs/ # NodeJS Lambda extensions
โ”‚ โ””โ”€โ”€ ... # Other AWS service extensions
โ”œโ”€โ”€ src-types/ # TypeScript type definitions
โ”œโ”€โ”€ lib-src/lambda/ # Lambda function source code
โ”œโ”€โ”€ scripts/ # Deployment utilities
โ””โ”€โ”€ docs/ # Docusaurus documentation

๐ŸŒ Environmentsโ€‹

The library supports six SDLC environments mapped to three core environments:

SDLC EnvCore EnvDeploymentDescription
devdevAll-at-onceDevelopment
testdevAll-at-onceTesting
stagingstagingCanary 10% 5minPre-production
qastagingCanary 10% 5minQA testing
preprodstagingCanary 10% 15minFinal validation
prodprodLinear 10% 10minProduction

See Context Strategy Guide for details.

๐Ÿ›๏ธ Architectureโ€‹

Blue-Green Deployment Patternโ€‹

Learn more in the Blue-Green Deployments Guide.

๐Ÿ“– Core Conceptsโ€‹

Context Strategyโ€‹

Automatically manages environment configuration and naming:

import { App } from 'sdlcs-aws-cdk-lib';

const app = new App();
console.log(app.contextStrategy.sdlc); // 'dev', 'staging', 'prod'
console.log(app.contextStrategy.sdlcCore); // 'dev', 'staging', 'prod'

โ†’ Context Strategy Guide

Extended Stackโ€‹

Automatic stack naming and resource tagging:

import { Stack } from 'sdlcs-aws-cdk-lib';

// Stack name automatically becomes: MyStack-dev (or MyStack-dev-feature-123)
const stack = new Stack(app, 'MyStack');

// Access context and package details
console.log(stack.contextStrategy.sdlc);
console.log(stack.packageDetails.version);

Blue-Green Lambdaโ€‹

Zero-downtime Lambda deployments:

import { BlueGreenLambda } from './lib/lambda/BlueGreenLambda';

const lambda = new BlueGreenLambda(stack, 'API', {
sdlc: stack.contextStrategy.sdlc,
functionName: 'my-api',
entry: './src/lambda/api/index.ts',
});

โ†’ Lambda Patterns Guide

๐Ÿ”ง NPM Scriptsโ€‹

Deploymentโ€‹

npm run deploy              # Deploy all stacks (requires --context stage=<env>)
npm run deploy:dev # Deploy to dev
npm run deploy:staging # Deploy to staging
npm run deploy:prod # Deploy to production
npm run diff # Show pending changes
npm run synth # Synthesize CloudFormation

Developmentโ€‹

npm run build               # Compile TypeScript
npm run watch # Watch mode
npm test # Run tests
npm run lint # Lint code

Deployment Managementโ€‹

npm run deployment:status   # Check deployment status
npm run deployment:rollback # Rollback deployment

Documentationโ€‹

npm run docs:dev            # Start documentation dev server
npm run docs:build # Build documentation
npm run docs:serve # Serve built documentation

๐Ÿงช Testingโ€‹

# Run all tests
npm test

# Test specific Lambda function
cd lib-src/lambda/exampleApi
npm test

See Lambda Patterns Guide for testing strategies.

๐Ÿ” Securityโ€‹

  • Lambda functions follow least-privilege IAM principles
  • GitHub Actions uses OIDC (no long-lived credentials)
  • Automatic security tagging via PackageJsonDetails
  • CloudWatch Logs for comprehensive audit trails

See GitHub OIDC Setup for CI/CD configuration.

๐Ÿค Contributingโ€‹

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit using Conventional Commits
  4. Push to your branch
  5. Open a Pull Request

Commit Conventionโ€‹

feat(lambda): add new API endpoint
fix(stack): correct IAM permissions
docs: update deployment guide
chore(deps): update aws-cdk-lib to 2.160.0

See Commit Convention for guidelines.

๐Ÿ“„ Licenseโ€‹

MIT License - see LICENSE file

๐Ÿ†˜ Supportโ€‹

๐Ÿ”— Additional Resourcesโ€‹