Skip to content

Instantly share code, notes, and snippets.

@ktstevenson
Created October 14, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ktstevenson/154fc5ba3970e099a3c1277e61858bbf to your computer and use it in GitHub Desktop.
Save ktstevenson/154fc5ba3970e099a3c1277e61858bbf to your computer and use it in GitHub Desktop.
Cloud-init directive to add AWS SSM checking at boot time
#cloud-config
write_files:
- content: |
#!/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
path: /var/lib/cloud/scripts/per-boot/ssmcheck.sh
owner: root:root
permissions: '0755'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment