简体   繁体   English

AWS CloudFormation CodePipeline、ParameterOverrides、将列表传递给嵌套堆栈

[英]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.

相关问题 如何将列表传递给AWS CloudFormation中的嵌套堆栈参数? - How to pass a list to a nested stack parameter in AWS CloudFormation? AWS Cloudformation将值传递给嵌套堆栈 - AWS cloudformation pass value to nested stack 将参数添加到 AWS CloudFormation / CodePipeline 堆栈 - Add parameter to an AWS CloudFormation / CodePipeline stack AWS CodePipeline:如何将CloudFormation操作的输出传递给CodeBuild操作 - AWS CodePipeline: How to pass output from CloudFormation action to a CodeBuild action 将堆栈标记传递给Cloudformation中的嵌套堆栈 - Pass stack tags to nested stack in Cloudformation AWS 无服务器框架:嵌套堆栈或 Cloudformation 模板 - AWS Serverless framework : Nested Stack or Cloudformation templates 在 AWS cloudformation 上理解 Apigateway 和嵌套堆栈时出错 - Error understanding Apigateway and nested stack on AWS cloudformation 将安全 SSM 参数传递给嵌套的 CloudFormation 堆栈 - Pass secure SSM parameter to a nested CloudFormation stack AWS Codepipeline 将 cloudformation 部署到开发账户并使用输出堆栈在中央账户中创建参数存储。 可能吗? - AWS Codepipeline deploy cloudformation to Dev account and use output stack to create Parameter store in Central account . Posible? CloudFormation 将所有参数从根堆栈传递到嵌套堆栈 - CloudFormation Pass All Parameters from Root Stack to Nested Stack
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM