简体   繁体   English

如何使用 YAML CloudFormation 模板在 API 网关 V2 资源上放置标签

[英]How to put Tags on API Gateway V2 Resources using a YAML CloudFormation Template

How to put Tags on the following Resources using a CloudFormation Template:如何使用 CloudFormation 模板将标签放在以下资源上:

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

For a generic AWS::ApiGatewayV2::Api Resource I have tried the following in the Resources section of the CloudFormation Template:对于通用 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

In the CloudFormation Events view of Amazon Management Console, The Resource failed with the following reason:在 Amazon 管理控制台的 CloudFormation 事件视图中,资源失败,原因如下:

Property validation failure: [Value of property {/Tags} does not match type {Map}]属性验证失败:[属性值 {/Tags} 与类型 {Map} 不匹配]

I looked up the Type, which appeared to be Json in the documentation :我在文档中查找了类型,它似乎是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

Which made me try the following:这让我尝试了以下方法:

 Tags: :Sub "{ \"TagKey1\", \"MyFirstTag\": \"TagKey2\" : \"${MySecondTagAsParameter}\"}"

That also did not work, prompting me to try YAML literals:这也不起作用,促使我尝试 YAML 文字:

 Tags: :Sub | { "TagKey1", "MyFirstTag": "TagKey2": "${MySecondTagAsParameter}" }

That did not work either.那也没有用。

The following did the trick:以下是诀窍:

 Tags: TagKey1: MyFirstTag TagKey2: !Ref MySecondTagAsParameter

You were very close to the json-like solution:您非常接近类似 json 的解决方案:

      Tags: { "TagKey1": "MyFirstTag",
              "TagKey2": !Ref MySecondTagAsParameter}

For me the following syntax worked:对我来说,以下语法有效:

Tags: 
  - 
    Key: "keyname1"
    Value: "value1"
  - 
    Key: "keyname2"
    Value: "value2"

Source: AWS Documentation资料来源: AWS 文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Cloudformation Pipeline YAML 模板中的 v2 配置与 GitHub 的连接? - How to configure a connection to GitHub using v2 from Cloudformation Pipeline YAML template? 如何在 CloudFormation yaml 模板中引用现有资源? - How to reference existing resources in CloudFormation yaml template? 如何使用 API 网关 v2 检查 http 请求方法 - How to check http request method using API Gateway v2 AWS Cloudformation Lambda + API 网关 V2:无法部署 API,因为此 API 中不存在路由 - AWS Cloudformation Lambda + API Gateway V2: Unable to deploy API because no routes exist in this API 如何将 api 网关(使用 api 密钥)添加到现有的 lambda cloudformation 模板? - how to add api gateway ( with api key) to an exiting lambda cloudformation template? AWS:使用 cloudformation 模板将 WAF 附加到 api 网关 - AWS: Attach WAF to api gateway using cloudformation template 在Cloudformation模板中将IAM角色用于AWS API Gateway - Using IAM Role for AWS API Gateway in Cloudformation Template 无法使用 cloudformation 模板在 api 网关方法中调用 lambda function - Unable to invoke lambda function in api gateway method using cloudformation template 如何在 API 网关 v2 中查看请求日志? - How can I view request log in API gateway v2? 如何将 Amazon HTTP API 网关 (v2) 中的 IP 地址列入白名单? - How to whitelist IP addresses in Amazon HTTP API Gateway (v2)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM