【问题标题】:AWS: A client error (ValidationError) occurred when calling the CreateStack operation: ParameterValue for ParameterKey ... is requiredAWS:调用 CreateStack 操作时发生客户端错误 (ValidationError):ParameterValue for ParameterKey ... 是必需的
【发布时间】:2014-03-08 03:01:40
【问题描述】:

我正在尝试创建一个 PowerShell 脚本,其中包括创建 AWS CloudFormation 堆栈。我在使用 aws cloudformation create-stack 命令时遇到问题,但是,它似乎没有获取参数。这是给我带来麻烦的sn-p:

$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" }
  },

我尝试了以下方法,但似乎都没有帮助:

  • 用静态值替换 $version
  • 将参数类型从数字更改为字符串
  • 试图以 JSON 格式传递参数列表

其中任何一个都没有骰子,同样的错误。就像它出于某种原因不接受参数一样。有什么想法吗?

【问题讨论】:

    标签: powershell amazon-web-services aws-powershell


    【解决方案1】:

    我敢打赌,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 )
    

    【讨论】:

    • Anthony - 感谢您的意见,这让我找到了正确的方向。该命令有效,但要求我使用 -TemplateURL 设置为上传到 S3 位置的模板,如下所示:New-CFNStack -StackName "cloud-$version" -TemplateURL "https://s3.amazonaws.com/.../my.template" -Parameters @( $p1 )
    猜你喜欢
    • 2020-01-16
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-22
    相关资源
    最近更新 更多