简体   繁体   English

参数值列表的 Lambda 函数

[英]Lambda function for list of values in Parameters

Im using below python code to create stack in AWS would like to send values as list/array for one of the parameter but im getting error as below:我使用下面的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

As you correctly observed, Type cannot be specified as a parameter in create_stack() .正如您正确观察到的那样,不能在create_stack()中将Type指定为参数。

Instead you should specify the type in the template TemplateURL='https://s3.amazonaws.com/****/**/myapp.json' so that the comma delimited value 'ParameterValue': 'subnet-1,subnet-2' is accepted.相反,您应该在模板TemplateURL='https://s3.amazonaws.com/****/**/myapp.json'指定类型,以便逗号分隔值'ParameterValue': 'subnet-1,subnet-2'被接受。

Example template that accepts CommaDelimitedList as a parameter.接受 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"
  }
}

In your case, the stack should be like this:在你的情况下,堆栈应该是这样的:

"Parameters" : {
  "Subnets": {
    "Description": "Comma-delimited list of CIDR blocks",
    "Type": "CommaDelimitedList",
    "Default": "10.0.48.0/24"
  }
}

Now you can create your stack, without specifying Type现在您可以创建您的堆栈,而无需指定Type

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM