This is a collection of TypeScript decorators for AWS Cloud Development Kit (CDK) that aims to make the code more aesthetically pleasing.
Note: This is not an official project from AWS.
This library is available on npm/yarn. To install it, run the following command:
npm install cdk-decorators
The library provides a set of decorators that can be used to annotate your CDK classes. Here's an example:
@TagWith('my-tag', 'my-value')
class TestStack extends Stack {
constructor(scope: any, id: string) {
super(scope, id);
new Bucket(this, 'MyBucket', {});
}
}
In this example, we're using the @TagWith
decorator to annotate the class. The @TagWith
decorator takes two arguments:
@TagWith(key?: string, value?: string)
: Adds a tag to all the resources in the stack with the specified key and value.
Adds a tag to all the resources in the stack with the specified key and value.
@TagWith('my-tag', 'my-value')
class TestStack extends Stack {
constructor(scope: any, id: string) {
super(scope, id);
new Bucket(this, 'MyBucket', {});
}
}
Adds aspects to the stack.
@Aspect((node: IConstruct) => {
if (node instanceof CfnBucket) {
node.bucketName = 'my-bucket';
}
})
class TestStack extends Stack {
constructor(scope: any, id: string) {
super(scope, id);
new Bucket(this, 'MyBucket', {});
}
}
Skips stack synthesis for the annotated class.
@Skip
class TestStack extends Stack {
constructor(scope: any, id: string) {
super(scope, id);
new Bucket(this, 'MyBucket', {});
}
}
Triggers a lambda function after the stack has been deployed.
@TriggerAfter({
code: Code.fromInline(`
exports.handler = async (event) => {
console.log('event: ', event)
};
`),
handler: 'index.handler',
runtime: Runtime.NODEJS_14_X,
})
class TestStack extends Stack {
constructor(scope: any, id: string) {
super(scope, id);
}
}
Prefixes all the resources in the stack with the specified string.
@PrefixWith('MyPrefix')
class TestStack extends Stack {
constructor(scope: any, id: string) {
super(scope, id);
new Bucket(this, 'Bucket', {});
}
}
Contributions are welcome! If you find a bug or have an idea for a new feature, feel free to open an issue or submit a pull request.
Before submitting a pull request, please make sure to run the tests:
yarn test
This library is licensed under the MIT License. See the LICENSE file for more information.