如何在CloudFormation中连接列表和ImportValue?

huangapple go评论54阅读模式
英文:

How to concatenate a list and ImportValue in CloudFormation?

问题

好的,这是交易的情况。我在 CloudFormation 模板中遇到了困难。

在我的模板中,我有类似这样的东西:

```YAML
Parameters:
  SecurityGroupIds:
    Type: List<AWS::EC2::SecurityGroup::Id>
Resources:
  Service:
    Type: AWS::ECS::Service
    Properties:
      NetworkConfiguration:
        AwsvpcConfiguration:
          SecurityGroups: !Join [ ",", [ !Ref "SecurityGroupIds", !ImportValue !Sub "${param1}-${param2}-efs-SecurityGroupId" ] ]

然后对于我的参数文件:

{
  {
    "ParameterKey": "SecurityGroupIds",
    "ParameterValue": "sg-065f0903f9c1eeaa2,sg-09f820ab09fa69c5f"
  }
}

由 CloudFormation Stack 输出的值${param1}-${param2}-efs-SecurityGroupId 是类似sg-1234567890的字符串值。

我似乎无法得到正确的格式。我基本上想要将来自另一个 Stack 输出的值添加到 SecurityGroupIds 列表中。

我觉得我需要以某种方式“展开”SecurityGroupIds 列表,将值添加到其中,然后将其传递给 SecurityGroups 配置?


<details>
<summary>英文:</summary>

Ok, so here&#39;s the deal. I&#39;m struggling in a CloudFormation template.

My template, I have something like:

```YAML
Parameters:
  SecurityGroupIds:
  Type: List&lt;AWS::EC2::SecurityGroup::Id&gt;
Resources:
  Service:
    Type: AWS::ECS::Service
    Properties:
      NetworkConfiguration:
        AwsvpcConfiguration:
          SecurityGroups: !Join [ &quot;,&quot;, [ !Ref &quot;SecurityGroupIds&quot;, !ImportValue !Sub &quot;${param1}-${param2}-efs-SecurityGroupId&quot; ] ]

Then for my Parameters file:

{
  {
    &quot;ParameterKey&quot;: &quot;SecurityGroupIds&quot;,
    &quot;ParameterValue&quot;: &quot;sg-065f0903f9c1eeaa2,sg-09f820ab09fa69c5f&quot;
  }
}

And the value outputted by the CloudFormation Stack ${param1}-${param2}-efs-SecurityGroupId is a string value of something like sg-1234567890.

And I can't seem to get the right format. I essentially want to just add a value to the SecurityGroupIds list that comes from another Stack's output.

I feel like I need to somehow "explode" the SecurityGroupIds list, add to it, then pass it to the SecurityGroups configuration?

答案1

得分: 1

如果您正在寻找“explode”功能,请查看Split

对于您的情况,它应该看起来像这样:

!Join [",", [!Split [",", !Ref SecurityGroupIds], !ImportValue !Sub "${param1}-${param2}-efs-SecurityGroupId"]]
英文:

if you are looking for "explode" functionality then take a look at Split

For your case it should look like this:

!Join [&quot;,&quot;, [!Split [&quot;,&quot;, !Ref SecurityGroupIds], !ImportValue !Sub &quot;${param1}-${param2}-efs-SecurityGroupId&quot;]]

huangapple
  • 本文由 发表于 2023年4月4日 07:22:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/75924402.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定