Stopping services and EC2 instances with System Manager

Viewed 36

I’ve been given the task of automating the shutdown of remote services in parallel on multiple EC2 instances and then the shutdown of the EC2 instances themselves on which these services run, and then to be able to do the reverse on demand.

I’m supposed to use AWS System manager to do this. The requirements call for a python script to use a YAML file (or set of YAML files) to generate the necessary SSM documents, send the SSM documents to System manager, trigger the desired action(s), and then delete the SSM documents.

I know how to do most of the required actions individually, but the YAML is throwing me for a loop. The path is, for the most part, fairly standardized:

/APP_Root/apps/Service_name/current/bin/(stop.py|start.py|monitor.py)

but there are some infrastructure services that run from slightly different paths.

The following actions:

service shutdown;
EC2 instance shutdown;
EC2 instance startup;
service startup

need to be done in parallel because, in the case of EC2 and service startup, it needs to be completed within an hour (customer requirement).

I’m thinking that the YAML for the service shutdown should look something like this, but I don't have a lot of experience with YAML:

EC2_instance:
  service_name:
    - shutdown:
        command: [
          # Gracefully shutdown service
          "/APP_Root/apps/Service_name/current/bin/stop.py"
        ]
    - monitor:
        command: [
          # run monitor for logging purposes
          "/APP_Root/apps/Service_name/current/bin/monitor.py"
        ]
### rinse and repeat for each service on the node
0 Answers
Related