Skip to content

Commit

Permalink
fix(runners): retry aws metadata token download on Linux (#3408)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sdarwin authored Aug 8, 2023
1 parent 7f40b01 commit ef46827
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion modules/runners/templates/start-runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
## Retrieve instance metadata

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

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

Expand Down

0 comments on commit ef46827

Please sign in to comment.