AWS: A client error (ValidationError) occurred when calling the CreateStack operation: ParameterValue for ParameterKey ... is required

Jayoaichen picture Jayoaichen · Feb 28, 2014 · Viewed 8.2k times · Source

I'm trying to create a PowerShell script that among other things creates an AWS CloudFormation stack. I'm having trouble with the aws cloudformation create-stack command however, it doesn't seem to be picking up the parameters. Here is the snippet giving me trouble:

$version = Read-Host 'What version is this?'
aws cloudformation create-stack --stack-name Cloud-$version --template-body C:\awsdeploy\MyCloud.template --parameters ParameterKey=BuildNumber,ParameterValue=$version

The error I receive is:

aws : 
At C:\awsdeploy\Deploy.ps1:11 char:1
+ aws cloudformation create-stack --stack-name Cloud-$version --template-bo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

A client error (ValidationError) occurred when calling the CreateStack operation: ParameterValue for ParameterKey BuildNumber is required

I know the CloudFormation script is OK because I can execute it without issues via the AWS explorer. The parameters section looks like this:

"Parameters" : {
    "BuildNumber" : { "Type" : "Number" }
  },

I've tried the following, none of which seem to help:

  • replacing $version with a static value
  • changing the parameter type from Number to String
  • trying to pass the parameter list in JSON format

No dice on any of these, same error. It's like it's just not accepting the parameters for some reason. Any ideas?

Answer

Anthony Neace picture Anthony Neace · Feb 28, 2014

I'd wager that Powershell is having difficulty parsing that comma and loses the ParameterValue afterwards. You may want to try to wrap whole section after --parameter in a string (double-quoted, so $version still resolves):

aws cloudformation create-stack --stack-name Cloud-$version --template-body C:\awsdeploy\MyCloud.template --parameters "ParameterKey=BuildNumber,ParameterValue=$version"

Or, failing that, try running the line explicitly in the cmd environment.


If you're interested in an alternative solution, AWS has implemented their command line tools in a separate utility called AWS Tools for Powershell. create-stack maps to New-CFNStack as shown in this documentation: New-CFNStack Docs

It looks like this would be the equivalent call:

$p1 = New-Object -Type Amazon.CloudFormation.Model.Parameter 
$p1.ParameterKey = "BuildNumber" 
$p1.ParameterValue = "$version" 

New-CFNStack -StackName "cloud-$version" ` 
-TemplateBody "C:\awsdeploy\MyCloud.template" ` 
-Parameters @( $p1 )