Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelfecher/3f9adc6c7b60fed34d3af28ea53f979f to your computer and use it in GitHub Desktop.
Save michaelfecher/3f9adc6c7b60fed34d3af28ea53f979f to your computer and use it in GitHub Desktop.
AWS CDK - Configurabe values: Simple, independent (from deployment environment), but intransparent/
// source: https://github.com/michaelfecher/cdk-field-guide/blob/main/remove-hard-coded-values-and-use-variables/environment-variables/vpc-stack.ts
export class VpcStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
// reading the value from the env.
// Obviously, you have to set it before or pass it before you call any cdk command
const vpcCidr = process.env.VPC_CIDR;
new Vpc(this, 'VPC', {
maxAzs: 3,
// using the value
cidr: vpcCidr,
subnetConfiguration: [
{
name: 'App',
subnetType: SubnetType.PRIVATE,
cidrMask: 24
},
// ...
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment