gpt4 book ai didi

amazon-web-services - CloudFormation 将变量从一个堆栈传递到另一个堆栈

转载 作者:行者123 更新时间:2023-12-03 07:39:02 27 4
gpt4 key购买 nike

我有一种情况,我想将输出参数从一个堆栈传递到另一个堆栈的参数。我了解输出区域和 Fn::ImportValue,但我必须在堆栈 #2 中声明一个单独的变量,否则我会收到错误。

在堆栈 1 中:

Parameters:
EnvironmentName:
Type: String
Default: production
Description: "A friendly environment name that will be used for namespacing all cluster resources. Example: staging, qa, or production"

...

Outputs:
EnvironmentName:
Description: The deployment mode of this and subsequent stacks.
Value: !Ref EnvironmentName
Export:
Name: !Ref EnvironmentName

在堆栈 #2 中我有:

Parameters:
EnvironmentName:
Type: String
Default: production
Description: "A friendly environment name that will be used for namespacing all cluster resources. Example: staging, qa, or production"

我希望环境名称不必声明两次。但我做不到:

Parameters:
EnvironmentName:
Type: String
Default: Fn::ImportValue {$EnvironmentName}
Description: "A friendly environment name that will be used for namespacing all cluster resources. Example: staging, qa, or production"

我可以尝试一些事情,一篇文章建议使用 FindInMap 并将环境名称放入 map 中。这看起来很奇怪,而且我还没有尝试过。另一种方法是嵌套堆栈,但我不想最终得到一个巨大的模板文件。

最佳答案

你不能这么做。它根本不可能,并且 CFN 不支持参数默认值或映射中的函数。

关于amazon-web-services - CloudFormation 将变量从一个堆栈传递到另一个堆栈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74782972/

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