用于将标签传递给资源的 Cloudformation 模板参数

use*_*076 6 amazon-web-services aws-cloudformation

我一直在绞尽脑汁,但不知道如何做到这一点,这似乎很有限,但我希望能够有一个模板参数,可用于将任意标签传递给模板中支持的资源,例如:

EC2Tags:
  Description: Tags to add to the EC2 Instance
  Type: CommaDelimitedList
  Default: "CreatedBy=JohnDoe,Name=NewEC2,OtherTag=OtherValue"

 ....
Run Code Online (Sandbox Code Playgroud)

但后来资源需要类似的东西:

Type: "AWS::EC2::Instance"
Properties:
  Tags: 
    - 
     Key: "keyname1"
     Value: "value1"
    - 
     Key: "keyname2"
     Value: "value2" 

  ....
Run Code Online (Sandbox Code Playgroud)

有办法实现这个目标吗?

use*_*076 5

我想要一个通用的解决方案,不假设标签的数量、标签的顺序或标签名称,经过多次尝试和错误,我已经设法使用 @laurent-jalbert-simard 提出的自定义资源解决方案解决了这个问题。

如果其他人可能觉得有用,以下是要点:

https://gist.github.com/ispyinternet/97b434a2a58aea5d496ecd87b29e64e9


Lau*_*ard 1

不,我认为不能直接完成。但是,您可以创建一个简单的自定义资源,该资源可以采用您作为参数传递的标签并将它们应用到 EC2 实例。