My goal is to have an AWS System Manager Document download a script from S3 and then run that script on the selected EC2 instance. In this case, it will be a Linux OS.

According to AWS documentation for aws:downloadContent the sourceInfo Input is of type StringMap.

The example code looks like this:

{
  "schemaVersion": "2.2",
  "description": "aws:downloadContent",
  "parameters": {
    "sourceType": {
    "description": "(Required) The download source.",
    "type": "String"
  },
  "sourceInfo": {
    "description": "(Required) The information required to retrieve the content from the required source.",
    "type": "StringMap"
    }
  },
  "mainSteps": [
    {
      "action": "aws:downloadContent",
      "name": "downloadContent",
      "inputs": {
        "sourceType":"{{ sourceType }}",
        "sourceInfo":"{{ sourceInfo }}"
      }
    }
  ]
}

This code assumes you will run this document by hand (console or CLI) and then enter the sourceInfo in the parameter. When running this document by hand, anything entered in the parameter (an S3 URL) isn't accepted. However, I'm not trying to run this by hand, but rather programmatically and I want to hard code the S3 URL into sourceInfo in mainSteps.

AWS does give an example of syntax that looks like this:

{
"path": "https://s3.amazonaws.com/aws-executecommand-test/powershell/helloPowershell.ps1" 
}

I've coded the document action in mainSteps like this:

        {
            "action": "aws:downloadContent",
            "name": "downloadContent",
            "inputs": {
              "sourceType": "S3",
              "sourceInfo":
                {
                  "path": "https://s3.amazonaws.com/bucketname/folder1/folder2/script.sh"
                },
                "destinationPath": "/tmp"
            }
        },

However, it doesn't seem to work and I receive this error:

invalid format in plugin properties map[sourceInfo:map[path:https://s3.amazonaws.com/bucketname/folder1/folder2/script.sh] sourceType:S3]; error json: cannot unmarshal object into Go struct field DownloadContentPlugin.sourceInfo of type string

Note: I have seen this post that references how to format it for Windows. I did try it, didn't work and doesn't seem relevant to my Linux needs.

So my questions are:

  1. Do you need a parameter for sourceInfo of type StringMap - something that won't be used within the aws:downloadContent {{ sourceInfo }} mainSteps?
  2. How do you properly format the aws:downloadContent action sourceInfo StringMap in mainSteps?

Thank you for your effort in advance.

1

There are 1 best solutions below

0
On

I had similar issue as I did not want anyone to type the stuff when running. So I added a default to the download content

    "sourceInfo": {
  "description": "(Required) Blah.",
  "type": "StringMap",
  "displayType": "textarea",
  "default": {
    "path": "https://mybucket-public.s3-us-west-2.amazonaws.com/automation.sh"
  }
}