Skip to content

Commit dcf6109

Browse files
committed
Retry API Gateway force deployment on throttling
1 parent c14cb30 commit dcf6109

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

.github/workflows/deploy-backend-aws.yml

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,35 @@ jobs:
693693
--query 'Stacks[0].Outputs[?OutputKey==`ApiEndpoint`].OutputValue' \
694694
--output text)
695695
REST_API_ID=$(echo "$ENDPOINT" | sed -E 's#https://([^.]+)\.execute-api\..*#\1#')
696-
aws apigateway create-deployment \
697-
--rest-api-id "$REST_API_ID" \
698-
--stage-name "${{ env.ENVIRONMENT }}" \
699-
--description "github-actions-${GITHUB_RUN_ID}-${GITHUB_SHA}"
696+
for attempt in 1 2 3 4 5; do
697+
set +e
698+
OUTPUT=$(aws apigateway create-deployment \
699+
--rest-api-id "$REST_API_ID" \
700+
--stage-name "${{ env.ENVIRONMENT }}" \
701+
--description "github-actions-${GITHUB_RUN_ID}-${GITHUB_SHA}" 2>&1)
702+
STATUS=$?
703+
set -e
704+
705+
echo "$OUTPUT"
706+
707+
if [ "$STATUS" -eq 0 ]; then
708+
exit 0
709+
fi
710+
711+
if ! echo "$OUTPUT" | grep -q "TooManyRequestsException"; then
712+
echo "::error::API Gateway stage deployment failed with a non-retryable error"
713+
exit "$STATUS"
714+
fi
715+
716+
if [ "$attempt" -eq 5 ]; then
717+
echo "::error::API Gateway stage deployment hit AWS rate limits after 5 attempts"
718+
exit "$STATUS"
719+
fi
720+
721+
SLEEP_SECONDS=$((attempt * 15))
722+
echo "API Gateway rate limited create-deployment; retrying in ${SLEEP_SECONDS}s..."
723+
sleep "$SLEEP_SECONDS"
724+
done
700725
701726
- name: Get API Endpoint
702727
id: get-endpoint

0 commit comments

Comments
 (0)