[英]AWS CloudFormation CodePipeline, ParameterOverrides, pass list to a nested stack
[英]How to pass a list to a nested stack parameter in AWS CloudFormation?
我正在使用嵌套堆栈来创建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)
您的JSON格式不正确。 通过aws cloudformation validate-template
(甚至jsonlint.com )运行JSON会迅速发现一些基本语法错误:
Resources:{
要求密钥必须用引号引起来: "Resources": {
"subnet-1”,
需要用标准ASCII引号替换: "subnet-1",
"Properties"
在“ELBStack”资源对象"S3Object: {"Ref: "S3Bucket"},"
有需要被删除其最后一个元素之后尾随逗号: "S3Object: {"Ref: "S3Bucket"}"
您不能将列表传递给嵌套堆栈。 您必须像这样通过内部函数Join传递项目的串联: !Join ["separator", [item1, item2, …]]
。
在嵌套堆栈中,参数的类型需要为List<Type>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.