[英]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 模板将标签放在以下资源上:
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.