Home > database >  How do I obtain the properties of an existing Transit Gateway with the CDK?
How do I obtain the properties of an existing Transit Gateway with the CDK?

Time:10-07

I am deploying my app into an account that has a Transit Gateway shared from another AWS account via Resource Access Manager.

I want to create a Transit Gateway VPC Attachment to that Transit Gateway.

To create the Transit Gateway VPC Attachment object I need to supply a Transit Gateway ID. https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.CfnTransitGatewayVpcAttachment.html#class-cfntransitgatewayvpcattachment-construct

I cannot find a way with the CDK to obtain the Transit Gateway ID from an existing Transit Gateway. What method would I use to obtain the Transit Gateway ID?

CodePudding user response:

I do not see the method to "lookup" the existing Transit Gateway in https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-ec2.CfnTransitGateway.html

I assume you could either

  • Export the Transit Gateway ID as a CloudFormation output in the stack where it is created?
  • Lookup the Transit Gateway ID yourself and inject it into CDK source code?

I ended up with 2nd option in one of the projects and did not face any issues later.

CodePudding user response:

use your SDK to look it up.

During the deploy of a stack, use your languages SDK (such as boto3 for python) to access the AWS API commands to look up the information and retrieve it. I do this regularly with Layers that are identical across multiple stacks, but you need the version number to import a layer (i don't want to create multiple versions of the same layer) - I use boto3 to get the most recent version of the layer and the from_attributes command to import it into the stack.

You can do something similar with whatever SDK implimentation for your chosen languages replicates this CLI command: https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-transit-gateways.html

  • Related