1

I have been running into troubles when running a CLI command to create a AWS System Manager Association task. The command is the one listed below:

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 *)"

Every time I get an error that there is something wrong with parameters part but I have tried all combinations of quotes but couldn't find any fix for it.

Error parsing parameter '--parameters': Expected: '=', received: ''' for input: '{sourceType:[S3],sourceInfo:[{https://s3-eu-west-1.amazonaws.com/xxx/private/xxx.ps1"}],commandLine:[xxx]}'

Did someone faced a similar problem?

Mark B
  • 183,023
  • 24
  • 297
  • 295
slayer27
  • 65
  • 6

1 Answers1

1

The sourceInfo requires a list of strings. Be sure to escape any quotes within the string.

Instead of:

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

Use this:

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

It worked fine for me on a 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 *)"
    }
}
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • Sadly it still shows the same error, don't understand the quotes are not added when the error is triggered. Any point in adding debug for further details? – slayer27 Mar 01 '19 at 08:21
  • On a Mac, when I run your command with the above parameters, it successfully created the association. If you are on Windows, then the quotes will be slightly different (eg maybe try without the single quote?). – John Rotenstein Mar 01 '19 at 09:28
  • Yes, it seems I manage to make it work for Windows as well. Thanks for your help John. – slayer27 Mar 01 '19 at 12:56