【问题标题】:Set Endpoint ID in ApiGateway for a private type using cloudformation in python在 python 中使用 cloudformation 在 ApiGateway 中为私有类型设置端点 ID
【发布时间】:2020-02-22 11:58:18
【问题描述】:

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

ApiGateway:

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

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

【问题讨论】:

标签: amazon-web-services amazon-cloudformation aws-api-gateway boto3 amazon-vpc


【解决方案1】:

Cloudforamtion 不支持。这可以使用 boto3 api 网关客户端完成:

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

【讨论】:

    【解决方案2】:

    从这个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,了解向构造添加缺失功能的详细信息。

    【讨论】:

      猜你喜欢
      • 2017-11-12
      • 2017-07-19
      • 2018-07-10
      • 1970-01-01
      • 2020-10-19
      • 2018-11-24
      • 2010-10-01
      • 2023-03-07
      • 2015-06-09
      相关资源
      最近更新 更多