【问题标题】:How to pass list of Refs in CloudFormation JSON?如何在 CloudFormation JSON 中传递 Refs 列表?
【发布时间】:2021-07-25 06:41:58
【问题描述】:

我曾经有一个 CloudFormation 堆栈,它通过 VpcId 和 List<AWS::EC2::Subnet>(子网列表)。但后来我决定我真的希望我的堆栈创建自己的 VPC。所以我想出了这个:

{
  "PublicSubnetOne": {
    "Type": "AWS::EC2::Subnet",
    "Properties": {
      "VpcId": {"Ref": "VPC"},
      "CidrBlock": "10.0.0.0/24",
      "AvailabilityZone": {
        "Fn::Select": ["0", {"Fn::GetAZs": ""}]
      }
    }
  },
  "PublicSubnetTwo": {
    "Type": "AWS::EC2::Subnet",
    "Properties": {
      "VpcId": {"Ref": "VPC"},
      "CidrBlock": "10.0.0.0/24",
      "AvailabilityZone": {
        "Fn::Select": ["1", {"Fn::GetAZs": ""}]
      }
    }
  },
  "ApplicationLoadBalancer" : {
    "Type" : "AWS::ElasticLoadBalancingV2::LoadBalancer",
    "Properties" : {
      "Subnets" : { "Ref": "PublicSubnetOne,PublicSubnetTwo"}
    }
  },
}

这会导致以下错误:

模板Resources块中未解决的资源依赖[PublicSubnetOne,PublicSubnetTwo]

如何正确地将 List<> 的 Refs 传递给属性?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    试试这个:

    {"Ref": "PublicSubnetOne,PublicSubnetTwo"} [{“Ref”:“PublicSubnetOne”},{“Ref”:“PublicSubnetTwo”}]

    当您说 {"Ref": "PublicSubnetOne,PublicSubnetTwo"} 时,CloudFormation 会逐字查找名称为 "PublicSubnetOne,PublicSubnetTwo" 的内容。

    您可能对此感到困惑,因为it's totally fine to pass a Parameter with --parameter-overrides (from aws cloudformation deploy) with the value "vpc-someidhere,vpc-someidhere2",但它不适用于 refs。如果ParameterTypeList<>,我假设CloudFormation 将逗号分隔的字符串格式化为列表

    There's also an answer that has similar keywords 实际上建议将 (Fn::Join) 两个 ID 连接在一起,但我收到了类似 Subnets should be List of String 的错误

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-10
      • 2019-02-05
      • 2020-10-15
      • 2021-12-02
      • 2021-12-09
      • 2015-08-08
      • 2017-11-18
      • 2023-04-06
      相关资源
      最近更新 更多