shiv455
shiv455

Reputation: 7784

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),
    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

Upvotes: 1

Views: 1781

Answers (1)

helloV
helloV

Reputation: 52433

As you correctly observed, Type cannot be specified as a parameter in create_stack().

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.

Example template that accepts CommaDelimitedList as a parameter.

"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

Upvotes: 1

Related Questions