Skip to content

Instantly share code, notes, and snippets.

@hatchcanon
Created April 29, 2021 02:09
Show Gist options
  • Save hatchcanon/a90bae7d2c88ea55da7ec41ac1790cbc to your computer and use it in GitHub Desktop.
Save hatchcanon/a90bae7d2c88ea55da7ec41ac1790cbc to your computer and use it in GitHub Desktop.
list all the AWS instances that are missing the SSM agent
#!/bin/bash
for instance in $(aws ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId]' --output text )
do
managed=$(aws ssm describe-instance-information --filters "Key=InstanceIds,Values=$instance" --query 'InstanceInformationList[*].[AssociationStatus]' --output text)
if [[ "$managed" != "Success" ]]; then
managed=" Not Managed";
fi
aws ec2 describe-instances --instance-id $instance --output text --query 'Reservations[*].Instances[*].[InstanceId, Placement.AvailabilityZone, [Tags[?Key==`Name`].Value] [0][0], [Tags[?Key==`App`].Value] [0][0], [Tags[?Key==`Product`].Value] [0][0], [Tags[?Key==`Team`].Value] [0][0] ]'
echo " $managed"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment