我正在尝试创建一个PowerShell脚本,其中包括创建一个AWS CloudFormation堆栈。我遇到了aws CloudFormateCreate-堆栈命令的问题,但是,它似乎没有获取参数。这是给我添麻烦的片段:
$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" }
},我试过以下几种方法,但似乎都没有用:
没有骰子上任何这些,同样的错误。就好像是因为某种原因不接受参数一样。有什么想法吗?
发布于 2014-02-28 22:24:24
我敢打赌,Powershell在解析逗号时遇到了困难,之后失去了ParameterValue。您可能想尝试用字符串(双引号,因此$version仍然解析)将整个部分封装在一个字符串中:
aws cloudformation create-stack --stack-name Cloud-$version --template-body C:\awsdeploy\MyCloud.template --parameters "ParameterKey=BuildNumber,ParameterValue=$version"或者,如果失败了,就试试在cmd环境中显式运行行。吧。
如果您对另一种解决方案感兴趣,AWS已经在一个名为Powershell的AWS工具的单独实用程序中实现了它们的命令行工具。create-stack映射到New-CFNStack,如本文档所示:新的CFNStack文档
看起来,这将是一个等价的呼吁:
$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 )https://stackoverflow.com/questions/22106887
复制相似问题