armikl
armikl

Reputation: 81

Using boto3 to update a cloudformation template

I am trying to use boto3 to update an existing CloudFormation template, but my code fails on the 'Parameters' property! Here is what I have tried:

  1. Read params from a config file

    from ConfigParser import SafeConfigParser  
    parser = SafeConfigParser()  
    parser.optionxform=str  
    parser.read( '/parms/SecGrpsParams.cfg')  
    parms = dict(parser.items('params'))
    

print parms" produces

{'Application': 'Click2Buy', 'AdminCidr': '10.0.0.0/8', 'AppMoniker': 'c2b', 'vId': 'vpc-3bec005f'}

  1. Call update_stack

    client = boto3.client('cloudformation')  
    response = client.update_stack(  
        StackName = args.stackname,  
        TemplateURL = template,  
        Parameters = args.params,  
        Capabilities = ['CAPABILITY_IAM']  
     )
    
  2. And the code produces this error:
    botocore.exceptions.ParamValidationError: Parameter validation failed: Invalid type for parameter Parameters,
    value: {'Application': 'Click2Buy', 'AdminCidr': '10.0.0.0/8', 'AppMoniker': 'c2b', 'vId': 'vpc-3bec005f'},
    type: type: , valid types: ,

I have tried to args.params.items(), [args.params], and [args.params.items()] but can't figure out what is needed.

Upvotes: 3

Views: 8017

Answers (1)

armikl
armikl

Reputation: 81

I've discovered the problem with my pervious attempts. The "update_stack" call wants a list object passed to the 'Parameters' field in the form of Parameters = [{'ParameterKey':"parm_name", "ParameterValue":'parm_value'}]. And, the number of passed parameters must be an exact match of the Parameters definition in the CloudFormation template in number and syntax.

Upvotes: 5

Related Questions