【问题标题】:AWS Cloudformation: How to get a RestAPI nameAWS Cloudformation:如何获取 RestAPI 名称
【发布时间】:2019-05-19 11:58:19
【问题描述】:

目标

获取在 Cloudformation 堆栈中创建的 API GW 的名称。如果尝试获取 API GW 指标,则需要 API 名称,因为它们存在 By Api Name

.yaml 示例

TESTAPI:
    Type: AWS::ApiGateway::RestApi
    Properties:
      Description: 'test api'
      EndpointConfiguration:
        Types:
          - REGIONAL

问题

如果我调用!Ref TESTAPI,我会得到API ID,如果我调用!GetAtt TESTAPI.Name,错误是:“无效资源属性”

docs 不显示任何返回值。

【问题讨论】:

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


    【解决方案1】:

    除非 CloudFormation RestApi 资源被修改,否则不会提供 Name 属性。

    解决方法

    创建一个字符串 Parameter 来保存该字符串并强制执行 API 名称,稍后您可以使用 !GetAtt APIName.Value 引用它

    YAML 示例

    APIName:
        Type: AWS::SSM::Parameter
        Properties:
          AllowedPattern: "^[-a-zA-Z0-9 ]+$"
          Type: String
          Value: "Some API name"
    

    【讨论】:

      猜你喜欢
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      • 2019-04-10
      • 2014-05-14
      • 1970-01-01
      • 2015-04-27
      • 2020-03-13
      • 2018-02-24
      相关资源
      最近更新 更多