【问题标题】:AWS CLI Update_Stack can't pass parameter value containing a /AWS CLI Update_Stack 无法传递包含 / 的参数值
【发布时间】:2018-11-11 20:08:23
【问题描述】:

我整个早上都在努力尝试创建一个最终将更新 AWS 堆栈的 powershell 脚本。一切都很好,直到我必须将参数传递给 cloudformation 模板。

其中一个参数值 (ParameterKey=ZipFilePath) 包含 /。但是脚本失败并抱怨它期待一个=但找到了一个/。我尝试转义斜杠,但 API 抱怨它找到了反斜杠而不是等号。我哪里错了?

... <snip creating a zip file> ...

 $filename = ("TotalCommApi-" + $DateTime + ".zip")

aws s3 cp $filename ("s3://S3BucketName/TotalCommApi/" + $filename)

aws cloudformation update-stack --stack-name TotalCommApi-Dev --template-url https://s3-region.amazonaws.com/S3bucketName/TotalCommApi/TotalCommApiCFTemplate.json --parameters ParameterKey=S3BucketName,ParameterValue=S3BucketNameValue,UsePreviousValue=false ParameterKey=ZipFilePath,ParameterValue=("TotalCommApi/" + $filename) ,UsePreviousValue=false

cd C:\Projects\TotalCommApi\TotalComm_API

这里是 CloudFormation 模板中的相关部分:

    "Description": "An AWS Serverless Application that uses the ASP.NET Core framework running in Amazon Lambda.",
"Parameters": {
        "ZipFilePath": {
            "Type": "String",
            "Description": "Path to the zip file containing the Lambda Functions code to be published."
        },
        "S3BucketName": {
            "Type": "String",
            "Description": "Name of the S3 bucket where the ZipFile resides." 
        } 
},
"AWSTemplateFormatVersion": "2010-09-09",
"Outputs": {},
"Conditions": {},
"Resources": {
    "ProxyFunction": {
        "Type": "AWS::Lambda::Function",
        "Properties": {
            "Code": {
                "S3Bucket": {"Ref": "S3BucketName" },
                "S3Key": { "Ref": "ZipFilePath" }
            },

这是 PowerShell ISE 生成的错误消息

[图片已删除]

更新:我使用的是 Powershell 2 附带的 Windows 7。我升级到 Powershell 4。然后我的脚本产生了这个错误:

根据咨询公司的建议,我卸载了通过 msi 安装的 CLI,然后将 Python 升级到 3.6.2,然后通过 pip 重新安装了 CLI。我仍然得到同样的错误。我将命令“回显”到屏幕上,这就是我所看到的:

upload: .\TotalCommApi-201806110722.zip to s3://S3bucketName/TotalCommApi/TotalCommApi-201806110722.zip
aws
cloudformation
update-stack
--stack-name
TotalCommApi-Dev
--template-url
https://s3-us-west-2.amazonaws.com/s3BucketName/TotalCommApi/TotalCommApiCFTemplate.json
--parameters
ParameterKey=S3BucketName
UsePreviousValue=true
ParameterKey=ZipFilePath
ParameterValue=TotalCommApi/TotalCommApi-201806110722.zip

【问题讨论】:

  • 如果没有模板示例,这真的很难调试。可以分享一下吗?
  • @JohnNicely 我从上面的 CloudFormation 模板中添加了相关部分。请注意,当我使用控制台更新堆栈时,模板按预期工作。我能够在控制台中提供与脚本中相同的值,并且控制台成功更新堆栈。感谢您的回复。
  • @JohnNicely 我发现你必须用双引号将参数列表括起来,否则 PowerShell 会去掉逗号。我认为这可以解决我的问题,但它不会抱怨我没有为 ZipFileName 参数提供值。我好像赢不了我会相应地更新原始帖子。
  • 解决方法:停止使用Windows! /s
  • 别开玩笑了,您可能想试一试 Bash 子外壳,看看是否可以让它工作 - 当我试图重现您的问题时,我正在使用 Bash,但我没有有任何问题(除了我在回答中提到的问题)。

标签: amazon-web-services powershell amazon-s3 amazon-cloudformation aws-cli


【解决方案1】:

很抱歉延迟回复您 - 好消息是我可能对您的问题有所提示。

ParameterKey=ZipFilePath,ParameterValue=("TotalCommApi/" + $filename) ,UsePreviousValue=false

试图重现这个问题,我快把自己逼疯了。为什么?因为我假设("TotalCommApi/" + $filename) 之后的空格是复制的产物,而不是您使用的实际值。当我在以下位置添加空格时:

aws cloudformation update-stack --stack-name test --template-url https://s3.amazonaws.com/test-bucket-06-09/test.template --parameters ParameterKey=S3BucketName,ParameterValue=$bucketname,UsePreviousValue=false ParameterKey=ZipFilePath,ParameterValue=testfolder/$filename ,UsePreviousValue=false
Error parsing parameter '--parameters': Expected: '=', received: ','

这不完全是您的错误消息(而不是 /),但我认为在您的情况下这可能是一个类似的问题 - 检查以确保您的命令中使用的值在某处没有多余的空格.

【讨论】:

  • 我非常感谢您的努力。我做了很多改变都无济于事。我已经相应地更新了我的原始帖子。我联系了亚马逊,他们也无法重现我的错误。
猜你喜欢
  • 2017-07-12
  • 2017-08-29
  • 1970-01-01
  • 2017-02-17
  • 1970-01-01
  • 2015-12-21
  • 2016-11-30
  • 2019-02-22
  • 2021-08-09
相关资源
最近更新 更多