Skip to content

Instantly share code, notes, and snippets.

@ranman
Created June 11, 2020 15:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ranman/6e2b09161babd5d2d59d9d4ab7c28cfe to your computer and use it in GitHub Desktop.
Save ranman/6e2b09161babd5d2d59d9d4ab7c28cfe to your computer and use it in GitHub Desktop.
export class BaseStack extends cdk.Stack {
public readonly stageName?: string;
public readonly serviceName?: string;
constructor(scope: cdk.Construct, id: string, props: IBaseStack) {
const superProps = {
...(props.stageName && { stackName: `${props.stageName}-${id}` }),
...props,
};
super(scope, id, superProps);
if (props.stageName) {
this.stageName = props.stageName;
cdk.Tag.add(this, "Stage", props.stageName);
}
if (props.serviceName) {
this.serviceName = this.serviceName;
cdk.Tag.add(this, "Service", props.serviceName);
}
}
public allocateLogicalId(element: cdk.CfnElement) {
const orig = super.allocateLogicalId(element);
return this.stageName ? this.stageName + orig : orig;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment