[英]AWS CloudFormation CodePipeline, ParameterOverrides, pass list to a nested stack
The scope of the question:问题范围:
AWS CodeBuild, ParametersOverrides section AWS CodeBuild,ParametersOverrides 部分
Using Parameter Override Functions with CodePipeline Pipelines 在 CodePipeline 管道中使用参数覆盖函数
1) I can pass a string to ParameterOverrides, and then pass them to a nested stack, as it is described below 1) 我可以将字符串传递给 ParameterOverrides,然后将它们传递给嵌套堆栈,如下所述
-create a string parameter - 创建一个字符串参数
-pass it to ParameterOverrides section of the AWS CodeBuild project - 将它传递给 AWS CodeBuild 项目的 ParameterOverrides 部分
-parse parameter in the nested stack -parse 嵌套堆栈中的参数
Quoting the official documentation: AWS::CloudFormation::Stack引用官方文档: AWS::CloudFormation::Stack
If you use the Ref function to pass a parameter value to a nested stack, comma-delimited list parameters must be of type String.
如果使用 Ref 函数将参数值传递到嵌套堆栈,则逗号分隔的列表参数必须是 String 类型。 In other words, you cannot pass values that are of type CommaDelimitedList to nested stacks.
换句话说,您不能将 CommaDelimitedList 类型的值传递给嵌套堆栈。
2) I can not figure out on how to transform a List to a string inside a ParameterOverrides section with the configuration below: 2)我无法弄清楚如何使用以下配置将 List 转换为 ParameterOverrides 部分中的字符串:
-define a Parameter with type of list ServiceSubnets: Type: List Description: Subnets associated with the service - 定义类型为列表 ServiceSubnets 的参数:类型:列表描述:与服务关联的子网
-try to pass a parameter inside ParameterOverrides section as a value to a nested stack, apply Join function to transform it to a string - 尝试将 ParameterOverrides 部分中的参数作为值传递给嵌套堆栈,应用 Join 函数将其转换为字符串
ParameterOverrides: !Sub | { "ImageURI" : { "Fn::GetParam" : [ "BuildOutput", "imageDetail.json", "ImageURI" ] }, "ApplicationRepoName": "${ApplicationRepoName}", "Cluster": "${Cluster}", "ListenerArn": "${ListenerArn}", "TargetGroup": "${TargetGroup}", "ServiceDesiredCount": "${ServiceDesiredCount}", "ServiceLoadBalancerPath": "${ServiceLoadBalancerPath}", "ServiceContainerPort": "${ServiceContainerPort}", "ServiceSecurityGroups": { "Fn::Join" : [ ",", "${ServiceSecurityGroups}"] ] }, "ServiceSubnets": { "Fn::Join" : [ ",", "${ServiceSubnets}" ] }, "TaskContainerPort": "${TaskContainerPort}", "TaskCpu": "${TaskCpu}", "TaskMemory": "${TaskMemory}", "TaskExecutionRoleArn": "${TaskExecutionRoleArn}" }
So I expect that the List should be transformed to a String and String should be passed and then used in the nested stack, however, attempt to deploy such stack returned an error:所以我希望应该将 List 转换为 String 并且应该传递 String 然后在嵌套堆栈中使用,但是,尝试部署此类堆栈返回错误:
Template error: variable ServiceSecurityGroups in Fn::Sub expression does not resolve to a string
模板错误:Fn::Sub 表达式中的变量 ServiceSecurityGroups 未解析为字符串
My question:我的问题:
Is it possible to use Join function inside ParameterOverrides section to transform a List to a String?是否可以在 ParameterOverrides 部分中使用 Join 函数将列表转换为字符串?
If yes, I would much appreciate if you share with me some example that illustrates how to do this.如果是,如果您与我分享一些说明如何执行此操作的示例,我将不胜感激。
Thank you.谢谢你。
Unfortunately you cannot use intrinsic functions within the Fn::Sub Syntax Reference不幸的是,您不能在 Fn::Sub 语法参考中使用内部函数
You can still use other intrinsic functions such as Fn::Join within Fn::Sub variable map.您仍然可以在 Fn::Sub 变量映射中使用其他内部函数,例如 Fn::Join。 So your ParameterOverrides will be as follows instead:
因此,您的 ParameterOverrides 将如下所示:
ParameterOverrides: !Sub
- |
{
"ImageURI" : { "Fn::GetParam" : [ "BuildOutput", "imageDetail.json", "ImageURI" ] },
"ApplicationRepoName": "${ApplicationRepoName}",
"Cluster": "${Cluster}",
"ListenerArn": "${ListenerArn}",
"TargetGroup": "${TargetGroup}",
"ServiceDesiredCount": "${ServiceDesiredCount}",
"ServiceLoadBalancerPath": "${ServiceLoadBalancerPath}",
"ServiceContainerPort": "${ServiceContainerPort}",
"ServiceSecurityGroups": "${KEY_NAME_1}",
"ServiceSubnets": "${KEY_NAME_2}",
"TaskContainerPort": "${TaskContainerPort}",
"TaskCpu": "${TaskCpu}",
"TaskMemory": "${TaskMemory}",
"TaskExecutionRoleArn": "${TaskExecutionRoleArn}"
}
- KEY_NAME_1: !Join [ ",", [ !Ref ServiceSecurityGroups ] ]
KEY_NAME_2: !Join [ ",", [ !Ref ServiceSubnets ] ]
If your ServiceSecurityGroups and ServiceSubnets are already lists then remove the square braces around the !Ref statements.如果您的 ServiceSecurityGroups 和 ServiceSubnets 已经是列表,则删除 !Ref 语句周围的方括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.