pythonaws-cdkamazon-vpcaws-nat-gateway

How to lookup NAT Gateway by the tag name in AWS CDK


I am trying to whitelist the public IP of the NAT gateway that the VPC uses in the API Gateway resource policy of the lambda function. My AWS Account has a NAT Gateway which is already a part of the VPC. My main goal is to be able to get the public IP address of the NAT Gateway.

I am using fromLookup() to import VPC into the cdk.

I've looked through was documentation and noticed that NAT Gateway construct doesn't have the fromLookup() method. Also tried to access NAT Gateway through VPC attributes but seems like it's not there. This post seems promising: (stackoverflow post), but I can't figure out how to implement the suggestion.


Solution

  • It is indeed impossible to look up existing NAT GW using fromLookup().

    What you will have to do is combine CDK and SDK.

    What you need to do is install SDK :npm install aws-sdk

    And then use getNATGatewayPublicIP() function to fetch the public IP.