Skip to content

Instantly share code, notes, and snippets.

@Meroje
Forked from urjitbhatia/getec2lifecycle.sh
Last active May 21, 2019 16:32
Show Gist options
  • Save Meroje/6b7ce4ed8ec0406cc821189b4ddf3da9 to your computer and use it in GitHub Desktop.
Save Meroje/6b7ce4ed8ec0406cc821189b4ddf3da9 to your computer and use it in GitHub Desktop.
Check if an ec2 instance is spot or normal lifecycle
#!/usr/bin/env bash
aws ec2 describe-spot-instance-requests \
--filters Name=instance-id,Values="$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)" \
--region "$(wget -q -O - http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.region')" | \
jq -r '.SpotInstanceRequests | if length > 0 then "spot" else "normal" end'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment