在 python 中使用 cloudformation 在 ApiGateway 中为私有类型设置端点 ID

Set Endpoint ID in ApiGateway for a private type using cloudformation in python

我正在创建 YAML 格式的模板来创建堆栈。在 api 网关中,我想为私有类型的端点 ID 设置一个值。有没有办法在模板中做到这一点?或者我可以使用 boto3 来实现吗?

Api网关:

Type: 'AWS::ApiGateway::RestApi'
Properties:
  Description: A test API
  Name: !Ref ApiName
  EndpointConfiguration:
    Types:
      - "PRIVATE"
    vpcEndpointIds:
      - !Ref VPC

此代码给出错误,没有 属性 vpcEndpointIds。

Cloudforamtion 不支持 it.This 可以使用 boto3 api 网关客户端:

client_api_gateway.update_rest_api(restApiId=self.api_id,
                                            patchOperations=[
                                                {
                                                    'op': 'add',
                                                    'path': '/endpointConfiguration/vpcEndpointIds',
                                                    'value': vpc_endpoint_id
                                                }
                                            ])

从这个 cloudformation 文件看来它现在已被添加到 cloudformation。然而 aws-cdk 似乎没有反映此更新,但以下(未经测试)代码应该得到你想要的,假设 cloudformation 文档反映当前状态。

const api = new RestApi(this, 'APIGateway', {
    deploy: true,
    deployOptions: {
        stageName: 'live',
        tracingEnabled: true,
    },
    endpointTypes: [EndpointType.PRIVATE],
    retainDeployments: false,
    restApiName: 'my-api',
    description: 'an api',
});

const cfnApi = api.node.defaultChild as CfnMethod;

cfnApi.addOverride('Properties.EndpointConfiguration.VpcEndpointIds', ['12345']);

请参阅此处here,了解有关向构造添加缺失功能的详细信息。