SSM Runbooks and their BASH integration


I'm unable to add my bash code to the SSM Runbook/Automation Editor. The only place where i can find something similiar to what i need is in pre-defined templates from github. How can i add my own Code to these Runbooks? See my Screenshots below..

In this screenshot you can see that there's no way to add any code to the runbook eventhough i selected exactly the same values for this step as the in the 2nd screenshot. And yet, it won't let me input any code. My current View

This is a screenshot from the runbook i got from github. This is what i want in my own runbook. The desired View

please don't tell me i have to write all of the content manually....

2 Answers


I reviewed your ask along with the Github page that you referred, and tried to create an Automation Document. I was able to add the Bash Script onto the Step.

For you to do the same, please follow the below steps:

  1. Give a “Step Name”.
  2. Keep the “Action Type” on “Run a command on a managed instance”
  3. Keep the “Document name” field type “AWS-RunShellScript”.
  4. Let “Document name” and “InstanceIDs” also remain the same ie. AWS-RunShellScript and {{ START_QUERY_AWS_DBInstanceId.DBInstanceId }} respectively.
  5. Now, open “Additional inputs” and under “Input Name”, choose “Parameters” and add the below snippet in the “Input value”.


  • '#!/bin/bash'
  • 'SAPProfile=grep -o ''pf=[^[:space:]]*'' /usr/sap/sapservices | grep _HDB'
  • 'SID=echo ${SAPProfile} | awk -F "/" ''{print $4}'''
  • 'SYSTEMNO=echo ${SAPProfile} | awk -F "/" ''{print $7}'' | awk -F "_" ''{print $2}'' | sed ''s@^[^0-9]*\([0-9]\+\).*@\1@'''
  • 'echo "Running /usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function StartService ${SID}"'
  • '/usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function StartService ${SID}'
  • '/usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function WaitforServiceStarted 10 2'
  • 'echo "Running /usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function GetSystemInstanceList"'
  • '/usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function GetSystemInstanceList'
  • 'if [ $? -eq 0 ]'
  • then
  • 'echo "There is a system here, I am going to use start"'
  • '/usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function StartWait 600 2'
  • else
  • 'echo "There is no service running for instance number ${SYSTEMNO} "'
  • exit 1
  • fi
  • '/usr/sap/hostctrl/exe/sapcontrol -nr ${SYSTEMNO} -function GetProcessList'
  • 'if [ $? -eq 3 ]'
  • ' then'
  • ' echo "date +%F\ %T: The HANA Database Started Successfully"'
  • ' else'
  • ' echo "The return code was $? "'
  • ' exit 1'
  • ' fi'

(Note: Kindly note that the bullets that you observe are basically hyphens(-), and the above snippet is copied from SSMStopStartSAPv1.0.yml of the GitHub page:

  1. Similarly, you can now repeat the for the steps that require bash script to be included.

Thank you!

answered 2 years ago
  • i keep getting this error when trying to follow your instructions: is of type String, but expected type is StringMap. any idea why this might be?


I had the same problem today. I followed steps 1-4 from the previous answer but I was unable to add the commands as the input was expected as StringMap(Format : {"Env": "Prod"}).

This worked for me : Follow Previous post's steps 1-4 and then for Step-5: Click “Additional inputs” --> Under “Input Name”, choose “Parameters” and in the "Input Value" dialogue box add commands like this :

- '#!/bin/bash'
- 'command1'
- 'command2'

I directly entered the commands and I was missing the 'commands:' param in the Input Value, which is actually expected to be mentioned.

Alternatively, you can directly add the commands in the "Editor" section which is more easier. An example SSM Automation document :

schemaVersion: '0.3'
    type: String
  - name: RunCommand
    action: 'aws:runCommand'
      DocumentName: AWS-RunShellScript
        - i-xxxxx
          - '#!/bin/bash'
          - 'touch /home/ec2-user/ssm.txt'
          - 'echo {{VALUES}} >> /home/ec2-user/ssm.txt'
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions