如何使用 YAML CloudFormation 模板在 API Gateway V2 资源上添加标签

Had*_*ous 3 yaml amazon-web-services aws-cloudformation aws-api-gateway

如何使用 CloudFormation 模板在以下资源上添加标签:

  • AWS::ApiGatewayV2::Api
  • AWS::ApiGatewayV2::域名
  • AWS::ApiGatewayV2::Stage

对于通用 AWS::ApiGatewayV2::Api 资源,我在 CloudFormation 模板的资源部分尝试了以下操作:

MyApi:
  Type: 'AWS::ApiGatewayV2::Api'
  Properties:
    Name: MyApi
    ProtocolType: WEBSOCKET
    RouteSelectionExpression: $request.body.action
    ApiKeySelectionExpression: $request.header.x-api-key
    Tags:
      - Key: TagKey1
        Value: MyFirstTag
      - Key: TagKey2
        Value: !Ref MySecondTagAsParameter
Run Code Online (Sandbox Code Playgroud)

在 Amazon 管理控制台的 CloudFormation Events 视图中,资源失败,原因如下:

属性验证失败:[属性值 {/Tags} 与类型 {Map} 不匹配]

我查找了类型,它似乎在文档Json中:

Tags
  The collection of tags. Each tag element is associated with a given resource.
  Required: No
  Type: Json
  Update requires: No interruption
  Required: No
Run Code Online (Sandbox Code Playgroud)

这让我尝试了以下方法:

 Tags: !Sub "{ \"TagKey1\" : \"MyFirstTag\", \"TagKey2\" : \"${MySecondTagAsParameter}\"}"
Run Code Online (Sandbox Code Playgroud)

这也不起作用,促使我尝试 YAML 文字:

Tags: !Sub |
  {
    "TagKey1": "MyFirstTag",
    "TagKey2": "${MySecondTagAsParameter}"
  }
Run Code Online (Sandbox Code Playgroud)

那也不起作用。

Had*_*ous 6

下面的方法就成功了:

Tags:
  TagKey1: MyFirstTag
  TagKey2: !Ref MySecondTagAsParameter
Run Code Online (Sandbox Code Playgroud)