参数中值列表的 Lambda 函数

Lambda function for list of values in Parameters

我正在使用下面的 python 代码在 AWS 中创建堆栈 想为参数之一发送值作为 list/array 但我收到如下错误:

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

如您所见,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