File tree Expand file tree Collapse file tree 1 file changed +18
-5
lines changed
Expand file tree Collapse file tree 1 file changed +18
-5
lines changed Original file line number Diff line number Diff line change 44NONOK=1
55UNKNOWN=2
66
7- status_code=` curl --max-time 3 --silent --output /dev/stderr --write-out " %{http_code}" " http://169.254.169.254/latest/meta-data/spot/instance-action" `
7+ # Try to get IMDSv2 token (for AL2023)
8+ TOKEN=$( curl -X PUT " http://169.254.169.254/latest/api/token" \
9+ -H " X-aws-ec2-metadata-token-ttl-seconds: 21600" \
10+ --max-time 3 --silent --fail 2> /dev/null)
811
9- if [ " ${status_code} " -eq " 404" ]
10- then
12+ # Check spot termination notice
13+ if [ -n " $TOKEN " ]; then
14+ # Use IMDSv2 if token was obtained (AL2023)
15+ status_code=$( curl --max-time 3 --silent --output /dev/stderr --write-out " %{http_code}" \
16+ -H " X-aws-ec2-metadata-token: $TOKEN " \
17+ " http://169.254.169.254/latest/meta-data/spot/instance-action" )
18+ else
19+ # Fall back to IMDSv1 (Linux 2)
20+ status_code=$( curl --max-time 3 --silent --output /dev/stderr --write-out " %{http_code}" \
21+ " http://169.254.169.254/latest/meta-data/spot/instance-action" )
22+ fi
23+
24+ if [ " ${status_code} " -eq " 404" ]; then
1125 exit $OK
12- elif [ " ${status_code} " -eq " 200" ]
13- then
26+ elif [ " ${status_code} " -eq " 200" ]; then
1427 exit $NONOK
1528else
1629 exit $UNKNOWN
You can’t perform that action at this time.
0 commit comments