AWS System Manager CLI功能

时间:2019-02-28 13:29:38

标签: json amazon-web-services ssm

运行CLI命令来创建AWS System Manager Association任务时遇到麻烦。该命令是下面列出的命令:

aws ssm create-association --name AWS-RunRemoteScript --targets Key=instanceids,Values=i-03710c82b70551c32 --parameters '{"sourceType":["S3"],"sourceInfo":["{"path":\"https://s3-eu-west-1.amazonaws.com/xxx/private/xxx.ps1\"}"],"commandLine":["xxx.ps1"]}' --schedule-expression "cron(0 0 2 ? * SUN *)"

每次我都会收到错误消息,指出参数部分存在问题,但是我尝试使用所有引号组合,但找不到任何解决方法。

  

解析参数'--parameters'时出错:预期:'=',收到:'''   用于输入:   '{sourceType:[S3],sourceInfo:[{{https://s3-eu-west-1.amazonaws.com/xxx/private/xxx.ps1“}],commandLine:[xxx]}'

有人遇到过类似的问题吗?

1 个答案:

答案 0 :(得分:0)

sourceInfo需要一个字符串列表。确保在字符串中转义所有引号。

代替:

'{"sourceType":["S3"],"sourceInfo":["{"path":\"https://s3-eu-west-1.amazonaws.com/xxx/private/xxx.ps1\"}"],"commandLine":["xxx.ps1"]}'

使用此:

'{"sourceType":["S3"],"sourceInfo":["{\"path\":\"https://s3-eu-west-1.amazonaws.com/xxx/private/xxx.ps1\"}"],"commandLine":["xxx.ps1"]}'

在Mac上对我来说效果很好:

$ aws ssm create-association --name AWS-RunRemoteScript --targets Key=instanceids,Values=i-03710c82b70551c32 --parameters '{"sourceType":["S3"],"sourceInfo":["{\"path\":\"https://s3-eu-west-1.amazonaws.com/xxx/private/xxx.ps1\"}"],"commandLine":["xxx.ps1"]}' --schedule-expression "cron(0 0 2 ? * SUN *)"
{
    "AssociationDescription": {
        "Name": "AWS-RunRemoteScript",
        "AssociationVersion": "1",
        "Date": 1551432508.365,
        "LastUpdateAssociationDate": 1551432508.365,
        "Overview": {
            "Status": "Pending",
            "DetailedStatus": "Creating"
        },
        "DocumentVersion": "$DEFAULT",
        "Parameters": {
            "commandLine": [
                "xxx.ps1"
            ],
            "sourceInfo": [
                "{\"path\":\"https://s3-eu-west-1.amazonaws.com/xxx/private/xxx.ps1\"}"
            ],
            "sourceType": [
                "S3"
            ]
        },
        "AssociationId": "5de73031-a390-4e7f-8b99-8064584e84cb",
        "Targets": [
            {
                "Key": "instanceids",
                "Values": [
                    "i-03710c82b70551c32"
                ]
            }
        ],
        "ScheduleExpression": "cron(0 0 2 ? * SUN *)"
    }
}