From 86772ab32aba190a1e5451a37c4e372f361dc5f7 Mon Sep 17 00:00:00 2001 From: nai-degen Date: Tue, 10 Sep 2024 16:07:13 -0500 Subject: [PATCH] adds 503 as a 'successful' AWS keychecker response to deal with temporary outages --- src/shared/key-management/aws/checker.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/shared/key-management/aws/checker.ts b/src/shared/key-management/aws/checker.ts index 6541286..eee1168 100644 --- a/src/shared/key-management/aws/checker.ts +++ b/src/shared/key-management/aws/checker.ts @@ -269,7 +269,7 @@ See https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference- method: "POST", url: POST_INVOKE_MODEL_URL(creds.region, model), data: payload, - validateStatus: (status) => [400, 403, 404].includes(status), + validateStatus: (status) => [400, 403, 404, 503].includes(status), }; config.headers = new AxiosHeaders({ "content-type": "application/json", @@ -281,6 +281,18 @@ See https://docs.aws.amazon.com/bedrock/latest/userguide/cross-region-inference- const errorType = (headers["x-amzn-errortype"] as string).split(":")[0]; const errorMessage = data?.message; + // 503 ServiceUnavailableException errors are usually due to temporary + // outages in the AWS infrastructure. However, because a 503 response also + // indicates that the key can invoke the model, we can treat this as a + // successful response. + if (status === 503 && errorType.match(/ServiceUnavailableException/i)) { + this.log.warn( + { key: key.hash, model, errorType, data, status, headers }, + "Model is accessible, but may be temporarily unavailable." + ); + return true; + } + // This message indicates the key is valid but this particular model is not // accessible. Other 403s may indicate the key is not usable. if (