Skip to content

Instantly share code, notes, and snippets.

@MichaelScovell
Created April 19, 2021 12:00
Show Gist options
  • Save MichaelScovell/d3ce1be3a56c15eb01b743b86efe8156 to your computer and use it in GitHub Desktop.
Save MichaelScovell/d3ce1be3a56c15eb01b743b86efe8156 to your computer and use it in GitHub Desktop.
modify-ec2-imdsv2.sh
#!/bin/bash
#Script that will configure existing EC2 instances to IMDSV2
#Create variable for instance ID
instanceID=$1
#Check to ensure that the instance is not blank
if [[ -n $instanceID ]];
then
#Add IMDSV2
aws ec2 modify-instance-metadata-options \
--instance-id ${instanceID} \
--http-tokens required \
--http-endpoint enabled
else
#Return this message and exit the script
echo "The instanceID is blank. Please try passing in the ID when running the script"
exit -1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment