gpt4 book ai didi

amazon-web-services - 如何将列表传递给 AWS CloudFormation 中的嵌套堆栈参数?

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

我使用嵌套堆栈来创建 ELB 和应用程序堆栈...并且我需要将子网列表传递给 ELB 和应用程序堆栈...

主要 json 具有以下代码...

"Mappings":{
"params":{

"Subnets": {
"dev":[
"subnet-1”,
"subnet-2”
],
"test":[
"subnet-3”,
"subnet-4”,
"subnet-5”,
"subnet-6”
],

"prod":[
"subnet-7”,
"subnet-8”,
"subnet-9”
]
}
}
},
"Parameters":{
"Environment":{
"AllowedValues":[
"prod",
"preprod",
"dev"
],
"Default":"prod",
"Description":"What environment type is it (prod, preprod, test, dev)?",
"Type":"String"
}
},
Resources:{
"ELBStack": {
"Type": "AWS::CloudFormation::Stack",
"Properties": {
"TemplateURL": {
"Fn::Join":[
"",
[
"https://s3.amazonaws.com/",
"myS3bucket",
"/ELB.json"
]
]
},
"Parameters": {
"Environment":{"Ref":"Environment"},

"ELBSHORTNAME":{"Ref":"ELBSHORTNAME"},
"Subnets":{"Fn::FindInMap":[
"params",
"Subnets",
{
"Ref":"Environment"
}
]},
"S3Bucket":{"Ref":"S3Bucket"},

},
"TimeoutInMinutes": "60"
}
}

现在,当我使用 lambda 或 cloudformation 运行此 json 时,我在 cloudformation 事件选项卡下收到以下错误...

 CREATE_FAILED AWS::CloudFormation::Stack   ELBStack    Value of property Parameters must be an object with String (or simple type) properties

using below lambda


import boto3
import time

date = time.strftime("%Y%m%d")
time = time.strftime("%H%M%S")
stackname = 'FulfillSNSELB'
client = boto3.client('cloudformation')
response = client.create_stack(
StackName= (stackname + '-' + date + '-' + time),
TemplateURL='https://s3.amazonaws.com/****/**/myapp.json',
Parameters=[
{
'ParameterKey': 'Environment',
'ParameterValue': 'dev',
'UsePreviousValue': False
}]
)

def lambda_handler(event, context):
return(response)

最佳答案

您无法将列表传递给嵌套堆栈。您必须使用内部函数 Join 传递一系列项目。像这样:!Join ["separator", [item1, item2, …]] .

嵌套栈中,参数的类型需要为List<Type> .

关于amazon-web-services - 如何将列表传递给 AWS CloudFormation 中的嵌套堆栈参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36166012/

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