gpt4 book ai didi

amazon-web-services - 模板错误: Every default member must be a string Coludformation yml

转载 作者:行者123 更新时间:2023-12-03 07:30:55 26 4
gpt4 key购买 nike

我正在尝试使用 yml 构建我的 cloudformation 脚本,我认为结果很好。但是,当我尝试使用此文件创建新堆栈时,它会给出模板错误:每个默认成员必须是字符串。我搜索了这个错误并尝试了多种方法,但没有成功。如果我在语法中遗漏了任何内容,请您提供您的输入。以下是我在 yml 文件中添加的内容。

基本上,我有 2 个参数 AccountAccessKey 和 AccountName,其中一个值用于非产品,另一个值用于产品,我试图通过定义映射并在参数部分中使用它们来动态获取该值。之后,我在第三部分中使用 $AccountAccessKey 和 $AccountName 来调用它们。

如有任何意见,我们将不胜感激。提前致谢

  AccountAccessKey:
Description: AccountAccessKey
Type: String
Default: !FindInMap [ AccountAccessKeyMap, !Ref "AWS::Region", !Ref Environment ]

AccountName:
Description: AccountName
Type: String
Default: !FindInMap [ AccountNameMap, !Ref "AWS::Region", !Ref Environment ]

AccountAccessKeyMap:
us-east-1:
dev: asdfsfsfasd4
qa: asdfsfsfasd4
prod: 88yuuiuyiui
us-west-2:
dev: asdfsfsfasd4
qa: asdfsfsfasd4
prod: 88yuuiuyiui

AccountNameMap:
us-east-1:
dev: nonprod
qa: nonprod
prod: prod1
us-west-2:
dev: nonprod
qa: nonprod
prod: prod1


"/usr/dev/agent/conf/info.xml":
content:
Fn::Sub:
- |
<?xml version="1.0" encoding="UTF-8"?>
<controller-info>
<account-access-key>${AccountAccessKey}</account-access-key>
<account-name>${AccountName}</account-name>
</controller-info>
- {Server: !FindInMap [ ServerMap, !Ref "AWS::Region", !Ref Environment ]}

最佳答案

我们不能使用intrinsic functions在参数中。在这种情况下,我们可以稍微重构映射并完全删除参数,因为无论如何我们都使用映射中的值。

!FindInMap [A​​ccountNameMap, !Ref AWS::Region, !Ref Environment] 用于模板本身内的其他属性。

AWSTemplateFormatVersion: "2010-09-09"
Description: "Test"
Parameters:
Environment:
Type: String
Default: dev

Mappings:
AccountAccessKeyMap:
us-east-1:
dev: mydeveastkey
qa: myqaeastkey
prod: myprodeastkey
us-west-2:
dev: mydevwestkey
qa: myqawestkey
prod: myprodwestkey
AccountNameMap:
us-east-1:
dev: mydeveastname
qa: myqaeastname
prod: myprodeastnaem
us-west-2:
dev: mydevwestname
qa: myqawestname
prod: myprodwestname
Resources:
SmsLambdaParameter:
Type: "AWS::SSM::Parameter"
Properties:
Name: !Sub
- "/${EnvFullUpper}/Lambda-Param/Test"
- { EnvFullUpper: !Ref Environment }
Type: "String"
Value: !Sub
- '<?xml version="1.0" encoding="UTF-8"?>
<controller-info>
<account-access-key>${AccountAccessKey}</account-access-key>
<account-name>${AccountName}</account-name>
</controller-info>
'
- {
AccountAccessKey:
!FindInMap [
AccountAccessKeyMap,
!Ref AWS::Region,
!Ref Environment,
],
AccountName:
!FindInMap [AccountNameMap, !Ref AWS::Region, !Ref Environment],
}

关于amazon-web-services - 模板错误: Every default member must be a string Coludformation yml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65729987/

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