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

Commit ef46827

Browse files
authored
fix(runners): retry aws metadata token download on Linux (#3408)
Adding more thorough logic to fully retry the aws metadata token download, on Linux. Continuing https://github.com/philips-labs/terraform-aws-github-runner/pull/3292. See explanation there. I have tested and it works, however Ubuntu usually succeeds. We will observe further how this goes or if more changes are needed.
1 parent 7f40b01 commit ef46827

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Diff for: modules/runners/templates/start-runner.sh

+13-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@
33
## Retrieve instance metadata
44

55
echo "Retrieving TOKEN from AWS API"
6-
token=$(curl --retry 20 -f -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 180")
6+
token=$(curl -f -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 180" || true)
7+
if [ -z "$token" ]; then
8+
retrycount=0
9+
until [ -n "$token" ]; do
10+
echo "Failed to retrieve token. Retrying in 5 seconds."
11+
sleep 5
12+
token=$(curl -f -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 180" || true)
13+
retrycount=$((retrycount + 1))
14+
if [ $retrycount -gt 40 ]; then
15+
break
16+
fi
17+
done
18+
fi
719

820
ami_id=$(curl -f -H "X-aws-ec2-metadata-token: $token" -v http://169.254.169.254/latest/meta-data/ami-id)
921

0 commit comments

Comments
 (0)