【发布时间】: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