
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@almamedia-open-source/cdk-project-stack
Advanced tools
Opinionated AWS CDK construct to define CloudFormation Stacks with sensible defaults
Opinionated AWS CDK construct to define CloudFormation Stacks with sensible defaults and tags.
Simplifies stack creation:
new MyStack(project, 'MyExampleStack', { summary: 'This is required' }); // extends ProjectStack, see "usage"
…by automatically setting Stack:
🚧 This tool is work-in-progress and experimental!
All @almamedia-open-source/cdk-
prefixed constructs/utilities are based on existing CDK constructs/utilities we've developed & used (in production) internally at Alma Media since 2019.
Breaking changes may occur at any given time without prior warning before first v1
major is released, as we rewrite them for CDK v2 and use this opportunity to also redesign & refactor.
Feedback is most welcome, but do note that we intend to implement these new constructs/utilities and their APIs in such manner that our existing CDK v1 production workloads can easily migrate into these new @almamedia-open-source/cdk-
constructs/utilities.
Ensure you meet following requirements:
v14.17.6
or newerv2.0.0
or newerInstall peer dependency @almamedia-open-source/cdk-project-context
:
npm i -D @almamedia-open-source/cdk-project-context
Install this tool:
npm i -D @almamedia-open-source/cdk-project-stack
Initialize your CDK App with Project
construct as documented in @almamedia-open-source/cdk-project-context
:
// bin/app.ts
import { Project } from '@almamedia-open-source/cdk-project-context';
// new Project instead of new App
const project = new Project({
name: 'my-cool-project',
author: {
organization: 'Acme Corp',
name: 'Mad Scientists',
email: 'mad.scientists@acme.example.com',
},
defaultRegion: 'eu-west-1', // defaults to one of: $CDK_DEFAULT_REGION, $AWS_REGION or us-east-1
accounts: {
dev: {
id: '111111111111',
config: {
baseDomain: 'example.net',
},
},
prod: {
id: '222222222222',
config: {
baseDomain: 'example.com',
},
},
},
})
Define your stack by extending ProjectStack
(instead of CDK's Stack
):
// lib/my-stack.ts
import { Construct } from 'constructs';
import { StackProps } from 'aws-cdk-lib';
import { ProjectStack } from '@almamedia-open-source/cdk-project-stack';
export class MyStack extends ProjectStack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
// define your resources...
}
}
Import and initialize your stack:
new MyStack(project, 'MyExampleStack', { summary: 'This is required' });
Run CDK commands with (optional) environment-type
(or shorthand: environment
or env
) CLI context flag, for example:
npx cdk deploy --context account=dev --context environment=staging
Resulting Stack properties
Property | Example value |
---|---|
stackName | "MyCoolProject-Environment-Staging-MyExampleStack" |
terminationProtection | true |
env.account | "111111111111" |
env.region | "eu-west-1" |
Resulting Tags for the Stack and its resources
Property | Example value |
---|---|
Account | dev |
Environment | staging |
Project | my-cool-project |
Author | Mad Scientists |
Organization | Acme Corp |
Contact | mad.scientists@acme.example.com |
You may always override these values by passing in regular CDK StackProps
; But, by default this construct aims to provide sensible defaults – making splitting CDK application into multiple stacks easier as you don't have to remember to specify all of these values for all the stacks.
Considering the example stack with no StackProps
(other than required description):
new MyStack(project, 'MyExampleStack', { description: 'This is required' });
The construct ID given to stack instance is used as a "base name" (e.g. MyExampleStack
) for the stack:
Runtime Context via CLI | Value |
---|---|
-c account=dev -c env=staging | MyCoolProject-Environment-Staging-MyExampleStack |
-c account=dev | MyCoolProject-Account-MyExampleStack |
- | MyCoolProject-MyExampleStack |
Stack Termination Protection is enabled for account stacks and long-lived & stable environmental stacks (belonging to either staging
or production
environment):
Runtime Context via CLI | Value | Explanation |
---|---|---|
-c account=dev -c env=staging | true | staging considered as long-lived & "stable" environment |
-c account=prod -c env=production | true | production considered as long-lived & "stable" environment |
-c account=dev -c env=development | false | short-lived development environment |
-c account=dev -c env=feature/foo-bar | false | short-lived development environment |
-c account=dev | true | account level resources (used by various environments) |
- | false | miscellaneous resources, often during initial development |
Account ID is resolved by @almamedia-open-source/cdk-project-context
matching the given -c account=key
to key in accounts
object defined in the Project
(App) initialization props:
{
// (unrelated configuration removed for brevity)
accounts: {
dev: {
id: '111111111111',
config: {
baseDomain: 'example.net',
},
},
prod: {
id: '222222222222',
config: {
baseDomain: 'example.com',
},
},
},
}
If Runtime Context via CLI --context account=key
not provided, you must specify account ID yourself into StackProps
:
new MyStack(project, 'MyExampleStack', {
summary: 'This is required',
env: {
account: '123456789012',
},
});
Region is resolved by @almamedia-open-source/cdk-project-context
. Basically in the following order:
defaultRegion
value in Project
(App) initialization$CDK_DEFAULT_REGION
environment variable$AWS_REGION
environment variableus-east-1
128 chars
If you're an Alma Media employee migrating from our internal CDK v1 constructs to this CDK v2 construct, read the following migration info:
Our internal (CDK v1) constructs used to have:
Capital Case
values for Project
(Name) Tag value, for example: My Cool Project
ProjectAndEnvironment
tagThis new CDK v2 construct sets the tag values in the same format & case style as provided in Project
configuration (so no case conversion) and it does not provide the combined ProjectAndEnvironment
tag anymore, this might potentially break some existing workloads: To solve this, you can control the casing by using a modifier context value in cdk.json
:
{
"context": {
"@almamedia-open-source/cdk-project-stack:legacyTags": true
}
}
But if you don't need the legacy tag style (i.e. the change does not break anything), just use the new tag convention. As always, be sure to view the diff of the changes and test the changes in multiple environments before deploying into production!
FAQs
Opinionated AWS CDK construct to define CloudFormation Stacks with sensible defaults
We found that @almamedia-open-source/cdk-project-stack demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.