Skip to content

Instantly share code, notes, and snippets.

@ktstevenson
Last active October 14, 2017 17:17
Show Gist options
  • Save ktstevenson/c3f2a2178e1fe33724b1e7cc64e7b64b to your computer and use it in GitHub Desktop.
Save ktstevenson/c3f2a2178e1fe33724b1e7cc64e7b64b to your computer and use it in GitHub Desktop.
Stop Amazon SSM agent if instance lacks basic SSM permissions
#!/bin/bash
REGION=$( curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | python -c "import sys, json; print json.load(sys.stdin)['region']" )
aws --region $REGION ssm list-associations --max-items 1 > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo "No privs to run Amazon SSM agent. Stopping..."
sudo stop amazon-ssm-agent
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment