Skip to content

Instantly share code, notes, and snippets.

@statik
Created May 13, 2021 15:04

Revisions

  1. statik created this gist May 13, 2021.
    41 changes: 41 additions & 0 deletions example.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    // 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',
    });