![](/img/trans.png)
[英]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.