'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)
               )


Solution 1:[1]

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)
           )

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DigVen