【问题标题】:How to pass in JSON type into yaml cloudformation template如何将 JSON 类型传入 yaml cloudformation 模板
【发布时间】:2020-12-16 22:14:05
【问题描述】:

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iot1click-placement.html#cfn-iot1click-placement-associateddevices

表示属性 AssociatedDevices 是 JSON 类型,但是当我在 YAML 中编写模板时

我在这里阅读了一些回复并尝试了以下方法:

AssociatedDevices: "--arguments": '{"SecuityButtonTemplate": !Ref TestITPA.DeviceId}'   
PlacementName: "TestITPAPlacement"      
Attributes:  "--arguments": '{"--Location": TestITPALoc}'

(构建失败)

还有这个:

  AssociatedDevices: '{"SecuityButtonTemplate": !Ref TestITPA.DeviceId}'   
  PlacementName: "TestITPAPlacement"
  Attributes:  '{"Location":"TestingLoc"}'

(这也无法构建)

我什至在 github 上搜索了引用 AssociatedDevices 的 YAML 代码,但没有找到人们实际上是如何做到这一点的 - 谁能帮我解释一下?

我终于试过了:

     AssociatedDevices: !Sub |
{
    SecuityButtonTemplate: !Ref TestITPA.DeviceId
}   
  PlacementName: "TestITPAPlacement"
  Attributes:  !Sub |
{
    Location: "testingLoc"
}

(这会引发似乎是 IDE 错误 - palcementName 的中间变量不再像其他变量那样是红色的)

【问题讨论】:

    标签: amazon-web-services yaml amazon-cloudformation


    【解决方案1】:

    您可以尝试以下方法:

    AssociatedDevices: !Sub '{"SecuityButtonTemplate": "${TestITPA.DeviceId}"}'  
    PlacementName: "TestITPAPlacement"
    Attributes: '{"Location":"TestingLoc"}'
    

    【讨论】:

    • 感谢我在 CloudFormation 中编译和部署了它 - 得到这个一般错误 The following resource(s) failed to create: [TestITPAPlacement]. 所以这可能是我需要更多研究的东西
    • @Kevin 没问题。好像是个新问题。如果您有更多详细信息,例如新的错误信息,您可以提出问题。顺便说一句,如果答案有帮助,我们将不胜感激。
    • 我也是这样工作的:AssociatedDevices: SecuityButtonTemplate: !GetAtt TestITPA.DeviceId PlacementName: "TestITPAPlacement" Attributes: Location: "TestingLoc"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-04
    • 2021-10-30
    • 2021-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-20
    相关资源
    最近更新 更多