[英]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).我正在尝试查找现有 VPC,检索所有私有子网(确保每个可用区中只有私有子网)。 Create VPC endpoint and later associate that with API gateway during creation of the API gateway.创建 VPC 终端节点,然后在创建 API 网关期间将其与 API 网关关联。 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) vpce-00c8fd5068629a5ab 不是有效的 VPC 终端节点 ID(服务:AmazonApiGateway;状态代码:400;错误代码:BadRequestException;请求 ID:ab287404-3002-41e5-8d93-e5792577d262;代理:null)
Also, I am able to create the VPC endpoint separately fine.另外,我可以单独创建 VPC 端点。 Able to create plain API gateway without associating with VPC endpoint fine as well.也能够创建普通的 API 网关,而无需与 VPC 端点相关联。
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".我需要使用正确的 API Gateway 服务端点,即“com.amazonaws.us-east-2.execute-api”。 So creating the VPC endpoint in below way fixed the issue:因此,以以下方式创建 VPC 端点解决了该问题:
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)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.