0

我有一些对流层代码,a)使用列表捕获​​安全组 ID 列表作为参数 b)创建一个新的安全组

groups = template.add_parameter(Parameter(
  "securityGroups",
  Type="List<AWS::EC2::SecurityGroup::Id>",
  Description="Security Groups for EC2 Instance",
))


ec2_sg = template.add_resource(
  ec2.SecurityGroup(
    'sg',
    GroupName = 'sg_test_app',
    GroupDescription = 'Test SG',
    VpcId = Ref(vpcid),
    Tags=Tags( **tags )
  )  
)

如果我参考 (a) 创建 EC2,则此方法有效:

inst_ec2 = template.add_resource(
  ec2.Instance(
    "EC2Instance",
    ImageId = 'ami-8b8c57f8',
    InstanceType = Ref(Type),
    IamInstanceProfile=Ref(instance_profile),
    SubnetId = Ref(snid),
    Tags=Tags(**tags),
    SecurityGroupIds = [ GetAtt(csso_ec2_sg, "GroupId") ],
    DependsOn = [
      'EC2InstanceProfile',
      'sg'
    ]
  )
)

如果我参考(b),这有效:

inst_ec2 = template.add_resource(
  ec2.Instance(
    "EC2Instance",
    ImageId = 'ami-8b8c57f8',
    InstanceType = Ref(Type),
    IamInstanceProfile=Ref(instance_profile),
    SubnetId = Ref(snid),
    Tags=Tags(**tags),
    SecurityGroupIds = groups,
    DependsOn = [
      'EC2InstanceProfile',
      'sg'
    ]
  )
)

但是,我不知道如何添加两者 - 这不起作用:

inst_ec2 = template.add_resource(
  ec2.Instance(
    "EC2Instance",
    ImageId = 'ami-8b8c57f8',
    InstanceType = Ref(Type),
    IamInstanceProfile=Ref(instance_profile),
    SubnetId = Ref(snid),
    Tags=Tags(**tags),
    SecurityGroupIds = [ GetAtt(csso_ec2_sg, "GroupId"), groups ],
    DependsOn = [
      'EC2InstanceProfile',
      'sg'
    ]
  )
)

谁能建议如何做到这一点?

4

1 回答 1

0

您可以尝试加入然后拆分列表。像这样的东西可能会起作用:

SecurityGroupIds = Split(",", Join(",", [Join(",", groups), GetAtt(csso_ec2_sg, "GroupId")]))
于 2017-12-03T01:49:54.253 回答