简体   繁体   English

AWS CDK:使用 VPC 接口端点创建 API 网关时出现异常

[英]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.

相关问题 在Terraform中创建接口类型VPC端点时出错(AWS提供程序) - Error while creating interface type vpc endpoint in terraform (aws provider) 通过VPC端点的AWS私有API网关 - AWS private API Gateway through VPC Endpoint AWS VPC 终端节点接口是否需要 Internet 网关 - Does an AWS VPC Endpoint Interface require an Internet Gateway 使用 AWS CDK,如何将 AWS 负载均衡器和 AWS 接口 VPC 终端节点连接在一起 - Using AWS CDK, How to connect an AWS Load balancer and an AWS Interface VPC Endpoint together 如果创建了 VPC 终端节点,则无法访问公共 AWS API 网关终端节点 - Unable to hit public AWS API gateway endpoints if a VPC Endpoint is created 我可以在VPC中将HTTP端点指定为AWS API Gateway中的资源吗? - Can I specify HTTP endpoint in a VPC as resource in AWS API Gateway? AWS API 网关配置来自不同区域的 vpc 端点 ID - AWS API gateway configure vpc endpoint id from different region AWS API 网关与资源策略 VS 与 VPC 端点 - AWS API Gateway with resource policy V.S. with VPC Endpoint 在cloudformation中将对API Gateway端点的访问限制为VPC - Restrict acces to API Gateway endpoint to VPC in cloudformation API Gateway 如何与 Firehose VPC 端点通信 - How API Gateway talk to Firehose VPC endpoint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM