2014-02-28 37 views
2

我试图创建一个PowerShell脚本,其中包括创建AWS CloudFormation堆栈。我在使用aws cloudformation create-stack命令时遇到了麻烦,但它似乎没有提取参数。下面是摘录给我找麻烦:AWS:调用CreateStack操作时发生客户端错误(ValidationError):需要ParameterKey ...的ParameterValue

$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 

我收到的错误是:

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 

我知道CloudFormation脚本是可以的,因为我可以不通过AWS资源管理问题执行它。参数部分看起来是这样的:

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

我试过以下,其中没有一个似乎帮助:

  • 用一个静态值
  • 改变从数参数类型替换$版本为String
  • 试图通过JSON格式

上任何一个没有骰子,同样的参数列表错误。这就像它只是因为某些原因不接受参数。有任何想法吗?

回答

3

我敢打赌,Powershell在解析该逗号时遇到了困难,之后失去了ParameterValue。你可能想尝试在一个字符串--parameter后换整段(双引号的,所以$version仍然解决):

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

或者,做不到这一点,尝试running the line explicitly in the cmd environment


如果你有兴趣的替代解决方案,AWS已经实施了他们的命令行工具称为AWS Tools for Powershell单独的实用程序。 create-stack映射到New-CFNStack如本文档中所示:New-CFNStack Docs

看起来这将是等同的调用:

$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) 
+0

- 安东尼感谢输入,这让我在正确的方向。该命令工作,但要求我使用-TemplateURL设置为上传到S3位置的模板,如下所示:'New-CFNStack -StackName“cloud-$ version” -TemplateURL“https://s3.amazonaws.com/。 ../my.template“ -Parameters @($ p1)' – Jayoaichen

相关问题