1

在运行 CLI 命令来创建 AWS System Manager 关联任务时,我遇到了麻烦。该命令是下面列出的命令:

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 "}],命令行:[xxx]}'

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

4

1 回答 1

1

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 *)"
    }
}
于 2019-02-28T23:35:33.403 回答