我使用下面的python代码在AWS中创建堆栈 想要为其中一个参数发送值作为列表/数组,但我得到如下错误:
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': 'Subnets',
'ParameterValue': 'subnet-1,subnet-2',
'Type':'CommaDelimitedList',
'UsePreviousValue': False
}]
)
def lambda_handler(event, context):
return(response)
module initialization error: Parameter validation failed:
Unknown parameter in Parameters[15]: "Type", must be one of: ParameterKey, ParameterValue, UsePreviousValue
答案 0 :(得分:1)
正如您所正确观察到的,Type
中的create_stack()
无法指定为参数。
相反,您应该在模板TemplateURL='https://s3.amazonaws.com/****/**/myapp.json'
中指定类型,以便接受以逗号分隔的值'ParameterValue': 'subnet-1,subnet-2'
。
接受CommaDelimitedList作为参数的示例模板。
"Parameters" : {
"DbSubnetIpBlocks": {
"Description": "Comma-delimited list of three CIDR blocks",
"Type": "CommaDelimitedList",
"Default": "10.0.48.0/24, 10.0.112.0/24, 10.0.176.0/24"
}
}
在你的情况下,堆栈应该是这样的:
"Parameters" : {
"Subnets": {
"Description": "Comma-delimited list of CIDR blocks",
"Type": "CommaDelimitedList",
"Default": "10.0.48.0/24"
}
}
现在您可以创建堆栈,而无需指定Type