gpt4 book ai didi

amazon-web-services - AWS CloudFormation CodePipeline、ParameterOverrides、将列表传递到嵌套堆栈

转载 作者:行者123 更新时间:2023-12-04 12:59:23 24 4
gpt4 key购买 nike

问题的范围:

AWS CodeBuild,ParametersOverrides 部分

Using Parameter Override Functions with CodePipeline Pipelines

1) 我可以将字符串传递给 ParameterOverrides, 然后将它们传递给嵌套堆栈,如下所述

-创建字符串参数

-将其传递到 AWS CodeBuild 项目的 ParameterOverrides 部分

-解析嵌套堆栈中的参数

引用官方文档: 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. In other words, you cannot pass values that are of type CommaDelimitedList to nested stacks.

2)我不知道如何将列表转换为字符串 在 ParameterOverrides 部分内,配置如下:

-定义列表类型的参数 服务子网: 类型:列表 描述:与服务关联的子网

- 尝试将 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}"
}

所以我希望列表应该转换为字符串和字符串应该传递然后在嵌套堆栈中使用,但是,尝试部署此类堆栈返回错误:

Template error: variable ServiceSecurityGroups in Fn::Sub expression does not resolve to a string

我的问题:

是否可以在 ParameterOverrides 部分中使用 Join 函数将列表转换为字符串?

如果是的话,如果您分享,我将不胜感激我举一些例子来说明如何做到这一点。

谢谢。

最佳答案

不幸的是,您不能在 Fn::Sub 中使用内部函数 Syntax Reference

您仍然可以在 Fn::Sub 变量映射中使用其他内部函数,例如 Fn::Join。因此您的 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 ] ]

如果您的 ServiceSecurityGroups 和 ServiceSubnets 已列出,则删除 !Ref 语句周围的方括号。

关于amazon-web-services - AWS CloudFormation CodePipeline、ParameterOverrides、将列表传递到嵌套堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60721197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com