SSM Runbooks and their BASH integration

0

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 年前檢視次數 485 次
2 個答案
1

Hello,

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”.

commands:

  • '#!/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: https://github.com/aws-samples/aws-ssm-automation-for-start-stop-sap)

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

Thank you!

AWS
支援工程師
已回答 2 年前
  • 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?

0

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 :

commands:
- '#!/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'
parameters:
  VALUES:
    type: String
mainSteps:
  - name: RunCommand
    action: 'aws:runCommand'
    inputs:
      DocumentName: AWS-RunShellScript
      InstanceIds:
        - i-xxxxx
      Parameters:
        commands: 
          - '#!/bin/bash'
          - 'touch /home/ec2-user/ssm.txt'
          - 'echo {{VALUES}} >> /home/ec2-user/ssm.txt'
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南