Created
May 13, 2021 15:04
-
-
Save statik/e41071a2da40c795bb73bc5ffff86a8e to your computer and use it in GitHub Desktop.
setting up CDK context values to make stack synth more deterministic rather than relying on runtime lookups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a pre-existing VPC network layout with stable ID, subnets, and routing tables | |
// this CDK setup code will populate the context necessary for lookups without going | |
// through synth and maintaining the context cache outside of version control | |
private setupFooVpcContext(): void { | |
// this is the CDK context info for the Demo VPC in the example account | |
const account = "1234" | |
const region = "us-west-2" | |
const tag = "MyDemoVPC" | |
const contextKey = | |
`vpc-provider:account=${account}:filter.tag:Name=${tag}:region=${region}:returnAsymmetricSubnets=true'; | |
const contextData = { | |
vpcId: 'vpc-TODO', | |
availabilityZones: [], | |
subnetGroups: [ | |
{ | |
name: 'Public', | |
type: 'Public', | |
subnets: [ | |
{ | |
subnetId: 'subnet-TODO', | |
availabilityZone: 'us-west-2a', | |
routeTableId: 'rtb-TODO', | |
}, | |
{ | |
subnetId: 'subnet-TODO', | |
availabilityZone: 'us-west-2b', | |
routeTableId: 'rtb-TODO', | |
}, | |
], | |
}, | |
], | |
}; | |
this.node.setContext(contextKey, contextData); | |
} | |
// then you can use code like | |
const vpc = Vpc.fromLookup(this, 'AVPC', { | |
vpcName: 'MyDemoVPC', | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment