【发布时间】:2018-03-09 11:21:10
【问题描述】:
我在 AWS windows EC2 堆栈创建 cloudformation 脚本的 userdata 部分编写了以下 powershell 脚本。我可以使用脚本安装 AWSCLI,但安装 cmdlet 后脚本无法识别“aws s3 cp”命令。 当我登录到 EC2 实例时,我能够从 powershell 提示符成功运行 aws s3 cp 命令。 谁能告诉我做错了什么。
{
"contents":[
"<powershell> ","\n",
"$awscliurl = \"https://s3.amazonaws.com/aws-cli/AWSCLI64.msi\" \n",
"$awsclidownloadloc = \"C:/Windows/Temp/AWSCLI64.msi\" \n",
"(New-Object System.Net.WebClient).DownloadFile($awscliurl, $awsclidownloadloc) \n",
"$argstr = \"/I C:\\Windows\\Temp\\AWSCLI64.msi /quiet /L*v ./awscli-output.log\" \n",
"Start-Process msiexec.exe -Wait -ArgumentList $argstr \n",
"Start-Process powershell.exe -RedirectStandardOutput c:\\s3out.txt -RedirectStandardError c:\\s3err.out -Wait -ArgumentList \"aws s3 cp s3://mybucket/myfile.exe c:\\myfile.exe\" \n",
"</powershell>"
]
}
当我查看 s3err.out 时,我看到以下内容
aws :术语“aws”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查 名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。 在行:1 字符:1 + aws s3 cp s3://mybucket/myfile.exe c:\myfile.exe + ~~~ + CategoryInfo : ObjectNotFound: (aws:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
【问题讨论】:
标签: powershell amazon-web-services amazon-s3