shiv455 shiv455 - 1 month ago 14x
Python Question

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:

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),
'ParameterKey': 'Subnets',
'ParameterValue': 'subnet-1,subnet-2',
'UsePreviousValue': False

def lambda_handler(event, context):

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().

Instead you should specify the type in the template TemplateURL='****/**/myapp.json' so that the comma delimited value 'ParameterValue': 'subnet-1,subnet-2' is accepted.

Example template that accepts CommaDelimitedList as a parameter.

"Parameters" : {
  "DbSubnetIpBlocks": {
    "Description": "Comma-delimited list of three CIDR blocks",
    "Type": "CommaDelimitedList",
    "Default": ",,"

In your case, the stack should be like this:

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

Now you can create your stack, without specifying Type