1

I’m setting up a patch process for EC2 servers running a web application.

I need to build an automated process that installs system updates but, reverts back to the last working ec2 instance if the web application fails a status check.

I’ve been trying to do this using an Automation Document in EC2 Systems Manager that performs the following steps:

  1. Stop EC2 instance
  2. Create AMI from instance
  3. Launch new instance from newly created AMI
  4. Run updates
  5. Run status check on web application
  6. If check fails, stop new instance and restart original instance

The Automation Document runs the first 5 steps successfully, but I can't identify how to trigger step 6? Can I do this within the Automation Document? What output would I be able to call from step 5? If it uses aws:runCommand, should the runCommand trigger a new automation document or another AWS tool?

sam
  • 11
  • 3

1 Answers1

0

I tried the following to solve this, which more or less worked:

  • Included an aws:runCommand action in the automation document
  • This ran the DocumentName "AWS-RunShellScript" with the following parameters:

Downloaded the script from s3:

sudo aws s3 cp s3://path/to/s3/script.sh /tmp/script.sh

Set the file to executable:

chmod +x /tmp/script.sh

Executed the script using variables set in, or generated by the automation document

bash /tmp/script.sh -o {{VAR1}} -n {{VAR2}} -i {{VAR3}} -l {{VAR4}} -w {{VAR5}}

The script included the following getopts command to set the inputted variables:

while getopts o:n:i:l:w: option
do
case "${option}"
in
n) VAR1=${OPTARG};;

o) VAR2=${OPTARG};;

i) VAR3=${OPTARG};;

l) VAR4=${OPTARG};;

w) VAR5=${OPTARG};;

esac

done

The bash script used the variables to run the status check, and roll back to last working instance if it failed.

sam
  • 11
  • 3