【问题标题】:AWS System Manager CLI functionAWS System Manager CLI 功能
【发布时间】:2019-02-28 13:29:38
【问题描述】:

我在运行 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"}],commandLine:[xxx]}'

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

【问题讨论】:

    标签: json amazon-web-services ssm


    【解决方案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 *)"
        }
    }
    

    【讨论】:

    • 遗憾的是它仍然显示相同的错误,不明白触发错误时没有添加引号。添加调试以获取更多详细信息有什么意义吗?
    • 在 Mac 上,当我使用上述参数运行您的命令时,它成功创建了关联。如果您使用的是 Windows,那么引号会略有不同(例如,可以尝试不使用单引号吗?)。
    • 是的,看来我设法使它也适用于 Windows。感谢您的帮助约翰。
    猜你喜欢
    • 2022-10-24
    • 2021-04-15
    • 2022-08-05
    • 2020-07-30
    • 1970-01-01
    • 1970-01-01
    • 2020-10-07
    • 2020-11-23
    • 1970-01-01
    相关资源
    最近更新 更多