Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.

Conversation

jaradtke-aws
Copy link

Issue #, if available:
The code to determine which Availability Zone (AZ) the node running this pod is in had not worked on a new deployment (Feb 2025). Troubleshooting indicated that the script was unable to determine the AZ. This update provides a method using IMDSv2

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html#instance-metadata-retrieval-examples

Description of changes:

# Am I on ec2 instances?
if [[ ${zone} == "unknown" ]]; then
-  # zone=$(curl -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | grep -o .$)
+  zone=$(TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | grep -o .$)
fi

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant