Skip to main content

Stack

sdlc-cdk-lib v1.0.0


sdlc-cdk-lib / src-extends-aws-cdk-lib/Stack

src-extends-aws-cdk-lib/Stack

Classes

Stack

Defined in: src-extends-aws-cdk-lib/Stack.ts:85

Extended AWS CDK Stack with automatic naming, tagging, and context management.

Remarks

This class extends the standard AWS CDK Stack to provide:

  • Automatic Stack Naming: Stack names include SDLC context (e.g., MyStack-dev, MyStack-staging-feature-123)
  • Context Strategy: Access to SDLC environment configuration (dev, staging, prod)
  • Package Details: Programmatic access to package.json metadata
  • Automatic Tagging: All resources tagged with SDLC, environment, and package information

The stack name format is <StackId>-<sdlcStage>, where sdlcStage includes the full context string (e.g., "dev-andrew", "staging-feature-123").

Examples

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

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

// Stack name will be: MyStack-dev (with --context stage=dev)
// Stack name will be: MyStack-dev-andrew (with --context stage=dev-andrew)
export class MyStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

// Access SDLC environment
const sdlc = this.contextStrategy.sdlc; // 'dev', 'staging', 'prod'
const stage = this.contextStrategy.sdlcStage; // 'dev-andrew'
const core = this.contextStrategy.sdlcCore; // 'dev', 'staging', 'prod'

// Access package metadata
console.log(this.packageDetails.name); // 'my-app'
console.log(this.packageDetails.version); // '1.0.0'
}
}
const stack = new Stack(app, 'MyStack', {
tags: {
Team: 'Platform',
CostCenter: '12345',
},
});

// Automatic tags applied:
// - SDLC: 'dev'
// - SDLC Core: 'dev'
// - PackageName: 'my-app'
// - PackageVersion: '1.0.0'
// Plus custom tags: Team, CostCenter

Extends

  • Stack

Constructors

Constructor

new Stack(scope, id, props?): Stack

Defined in: src-extends-aws-cdk-lib/Stack.ts:145

Creates a new extended Stack instance.

Parameters
scope

Construct

Parent construct (typically App)

id

string

Stack identifier (used in stack name as <id>-<sdlcStage>)

props?

StackProps

Optional stack properties including custom tags

Returns

Stack

Remarks

The stack name is automatically generated as <id>-<sdlcStage>. For example, with id='MyStack' and stage='dev-andrew':

  • Stack name: MyStack-dev-andrew
  • CloudFormation stack: MyStack-dev-andrew

All resources in the stack are automatically tagged with:

  • SDLC: Normalized SDLC stage
  • SDLC Core: Core environment
  • PackageName: Project name
  • PackageVersion: Project version
Throws

Error if stage context is not provided

Example
const app = new App();
const stack = new Stack(app, 'MyStack', {
env: {
account: process.env.CDK_DEFAULT_ACCOUNT,
region: process.env.CDK_DEFAULT_REGION,
},
tags: {
Project: 'MyProject',
},
});
Overrides

AwsStack.constructor

Properties

contextStrategy

readonly contextStrategy: ContextStrategy

Defined in: src-extends-aws-cdk-lib/Stack.ts:95

Context strategy providing SDLC environment configuration.

Remarks

Use this to access environment information:

  • sdlc: Normalized SDLC stage (dev, staging, prod, test, qa, preprod)
  • sdlcStage: Full stage string including context (dev-andrew, staging-feature-123)
  • sdlcCore: Core environment (dev, staging, prod)
packageDetails

readonly packageDetails: PackageJsonDetails

Defined in: src-extends-aws-cdk-lib/Stack.ts:108

Package details from package.json.

Remarks

Provides programmatic access to package metadata:

  • name: Package name
  • version: Package version
  • repoName: Repository name
  • author: Author information
  • license: License type

Methods

getPackageDetails()

getPackageDetails(): PackageJsonDetails

Defined in: src-extends-aws-cdk-lib/Stack.ts:190

Gets the package details for this stack.

Returns

PackageJsonDetails

PackageJsonDetails instance containing package.json metadata

Remarks

This is a convenience method equivalent to accessing this.packageDetails directly.

Example
const details = stack.getPackageDetails();
console.log(details.name, details.version);

Interfaces

StackProps

Defined in: src-extends-aws-cdk-lib/Stack.ts:14

Extended stack properties with additional configuration options.

Remarks

Extends AWS CDK StackProps with custom tagging support.

Extends

  • StackProps

Properties

tags?

readonly optional tags: object

Defined in: src-extends-aws-cdk-lib/Stack.ts:21

Custom tags to apply to the stack and all its resources.

Index Signature

[key: string]: string

Remarks

These tags are added in addition to automatic tags (SDLC, package metadata).

Overrides

AwsStackProps.tags