IMDSv1 and IMDSv2

IMDSv1 call

curl -i http://169.254.169.254/latest/meta-data/

IMDSv2 call

curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60"
 
curl -H "X-aws-ec2-metadata-token: xxxxxxxxxxxxxxxxxxx" -s http://169.254.169.254/latest/meta-data/

IMDSv2 call (onliner)

TOKEN=`curl -s -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 60"` && curl -i -H "X-aws-ec2-metadata-token: $TOKEN" -s http://169.254.169.254/latest/meta-data/

Check EC2 Instance configuration

aws ec2 describe-instances --instance-id i-xxxxxxxxx --query "Reservations[*].Instances[*].[InstanceId, IamInstanceProfile.Arn, MetadataOptions]"

Disable IMDSv1

aws ec2 modify-instance-metadata-options --instance-id i-xxxxxxxx --http-tokens required --http-endpoint enabled

Disable IMDSv1 and IMDSv2

aws ec2 modify-instance-metadata-options --instance-id i-xxxxxxxxxxxx --http-endpoint disabled