Search code examples
jsonstringamazon-web-servicesaws-ssm

SSM document execution using run command failed json: cannot unmarshal array into Go struct field RunScriptPluginInput.RunCommand of type string\"


I'm creating aws ssm document in json code for one of the application installation and configuration. SSM document execution using run command failed json: cannot unmarshal array into Go struct field RunScriptPluginInput.RunCommand of type string". Please note, i have added only some portion of the bash scripts, this is a lengthy script. The issue seems like something with the json code syntax. Great if anyone help on this?

{
  "schemaVersion": "2.2",
   "description": "SSM Document to install and configure xyz application",
     "parameters": {
  "TimeoutSeconds": {
  "type": "String",
  "description": "(Optional) The time in seconds for a command to be completed before it is considered to have failed.",
   "default": "3600"
  }
  },
  "mainSteps": [
    {
    "action": "aws:runShellScript",`
    "name": "runShellScript",     
        "timeoutSeconds": "{{ TimeoutSeconds }}",
        "runCommand": [
          "#/bin/bash",
           "aws configure set aws_access_key_id ${sts[0]} --profile $PROFILE",
          "aws configure set aws_secret_access_key ${sts[1]} --profile $PROFILE",
          "aws configure set aws_session_token ${sts[2]} --profile $PROFILE",
          "echo \"credentials stored in the profile named $PROFILE\"",
          "wget -c https://downloads.apache.org/tomcat/tomcat-9/v9.0.34/bin/apache-tomcat-9.0.34.tar.gz",
          "tar xf apache-tomcat-9.0.34.tar.gz -C /opt/tomcat",


Solution

  • This code is messy and impossible to deploy. Could you please underline the error message, and provide complex information about how you execute this document?

    1. content is unreadable, please reformate it... and please, close the sections - then anybody will be able to easily test your code.
    2. at the end of "action": "aws:runShellScript", you have additional, unexpected sign,
    3. you forgot about inputs property - https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-plugins.html#aws-runShellScript
    4. there should be #!/bin/bash instead #/bin/bash

    Anyway, finally, I did the above changes and it is working - I mean it's executable (on ec2 instance) - shell commands with aws cli don't work, as well as curl, which returns 404...

    I strongly recommend using yml standard, due to more readability and more build-in features.