英文:
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's the deal. I'm struggling in a CloudFormation template.
My template, I have something like:
```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" ] ]
Then for my Parameters file:
{
{
"ParameterKey": "SecurityGroupIds",
"ParameterValue": "sg-065f0903f9c1eeaa2,sg-09f820ab09fa69c5f"
}
}
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 [",", [!Split [",", !Ref SecurityGroupIds], !ImportValue !Sub "${param1}-${param2}-efs-SecurityGroupId"]]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论