【发布时间】:2020-05-09 13:13:23
【问题描述】:
我要做什么
我正在尝试使用 Windows 上的 AWS CLI 将 PowerShell 脚本从 GitHub 存储库中提取到 AWS EC2 实例上,然后在实例上运行该脚本。
我的尝试
我知道转义的双引号 (\") 是有效的,因为我尝试不使用它们无济于事。我还尝试将 --parameters 后面的 JSON 部分放在单独的文件中,然后将该文件加载到命令,但它抱怨在这种情况下格式化。
我在 PowerShell 和 Windows CMD 中都尝试过该命令(两者的语法不同,即使用双引号)。我在下面包含了这两种变体。
使用 AWS EC2 控制台,我可以使用图形界面让所有这些工作。现在的关键是让它也可以使用命令行工作。
这是 PowerShell 的命令:
aws ssm send-command --document-name "AWS-RunRemoteScript" --document-version "1" --targets "Key=instanceids,Values=<INSTANCE-ID>" --parameters '{\"sourceType\":[\"GitHub\"],\"sourceInfo\":{\"owner\":\"<USERNAME>\",\"repository\":\"Projects\",\"path\":\"test_script.ps1\"},\"commandLine\":[\".\\test_script.ps1\"],\"workingDirectory\":[""],\"executionTimeout\":[\"3600\"]}' --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --region us-east-2
问题似乎来自 --parameters 参数和它后面的 JSON。
这是 Git Bash 的命令(实际有效):
aws ssm send-command --document-name "AWS-RunRemoteScript" --document-version "1" --targets "Key=instanceids,Values=<INSTANCE-ID>" --parameters '{"sourceType":["GitHub"],"sourceInfo":["{\"owner\": \"<USERNAME>\", \"repository\": \"Projects\", \"path\": \"test_script.ps1\"}"],"commandLine":[".\\test_script.ps1"],"workingDirectory":[""],"executionTimeout":["3600"]}' --timeout-seconds 600 --max-concurrency "50" --max-errors "0" --region us-east-2
以下是产生的错误:
Parameter validation failed: Invalid type for parameter Parameters.sourceInfo, value: OrderedDict([('owner', '<USERNAME>'), ('repository', 'Projects'), ('path', 'test_script.ps1')]), type: <class 'collections.OrderedDict'>, valid types: <class 'list'>, <class 'tuple'>
如何以适当的格式指定这些参数?
【问题讨论】:
标签: json amazon-web-services powershell aws-cli