简体   繁体   中英

AWS CDK : Exception while creating API Gateway with VPC Interface Endpoint

I am trying to lookup for an existing VPC, retrieve all the private subnets (making sure there is only private subnet in each availability zone). Create VPC endpoint and later associate that with API gateway during creation of the API gateway. But getting the below exception when running the code.

vpce-00c8fd5068629a5ab is not a valid VPC endpoint id (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: ab287404-3002-41e5-8d93-e5792577d262; Proxy: null)

Also, I am able to create the VPC endpoint separately fine. Able to create plain API gateway without associating with VPC endpoint fine as well.

Please let me know what could be the issue.

vpc_retrieved = aws_ec2.Vpc.from_lookup(self, id="testvpcid",vpc_name="somevalidvpcname")

subnet_list = []
for subnet in vpc.private_subnets:
  subnet_list.append(subnet)

vpc_endpoint = aws_ec2.InterfaceVpcEndpoint(self, 
                 id="vpcendpoint", 
                 vpc=vpc_retrieved, 
                 service=aws_ec2.InterfaceVpcEndpointService(
                           name="com.amazonaws.us-east-2.lambda",port=80),
                 subnets=aws_ec2.SubnetSelection(subnets=subnet_list)
               )

vpc_endpoints = []
vpc_endpoints.append(vpc_endpoint)

vpc_endpoint_types = []
vpc_endpoint_types.append(aws_cdk.aws_apigateway.EndpointType.PRIVATE)

api_gateway = aws_cdk.aws_apigateway.RestApi(self, 
                id="cdktestapi",
                rest_api_name="cdk-test-api",
                endpoint_configuration= 
                   aws_cdk.aws_apigateway.EndpointConfiguration(                                                                       
                     types=vpc_endpoint_types,
                     vpc_endpoints=vpc_endpoints)
               )

The issue turned out to be a basic one. I needed to use the right API Gateway service endpoint which is "com.amazonaws.us-east-2.execute-api". So creating the VPC endpoint in below way fixed the issue:

vpc_endpoint = aws_ec2.InterfaceVpcEndpoint(self, 
             id="vpcendpoint", 
             vpc=vpc_retrieved, 
             service=aws_ec2.InterfaceVpcEndpointService(
                       name="com.amazonaws.us-east-2.execute-api",port=80),
             subnets=aws_ec2.SubnetSelection(subnets=subnet_list)
           )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM