concept security update in category aws

appears as: security updates, security update
Amazon Web Services in Action, Second Edition

This is an excerpt from Manning's book Amazon Web Services in Action, Second Edition.

When dealing with security updates, you may face either of these situations:

6.2.3. Installing security updates on running virtual machines

What do you do if you have to install a security update of a core component on tens or even hundreds of virtual machines? You could manually log in to all your VMs using SSH and run yum -y --security update or yum update-to [...], but if you have many machines or the number of machines grows, this can be annoying. One way to automate this task is to use a small script that gets a list of your VMs and executes yum in all of them. The following listing shows how this can be done in with the help of a Bash script. You can find the code in /chapter06/update.sh in the book’s code folder.

Listing 6.1. Installing security updates on all running EC2 instances
PUBLICIPADDRESSES="$(aws ec2 describe-instances \          #1
 --filters "Name=instance-state-name,Values=running" \
 --query "Reservations[].Instances[].PublicIpAddress" \
 --output text)"

for PUBLICIPADDRESS in $PUBLICIPADDRESSES; do
  ssh -t "ec2-user@$PUBLICIPADDRESS" \                     #2
 "sudo yum -y --security update"                         #3
done