( client: SecretsManagerClient, secretId: string )
| 64 | } |
| 65 | |
| 66 | async function sendWithRetry( |
| 67 | client: SecretsManagerClient, |
| 68 | secretId: string |
| 69 | ): Promise<GetSecretValueCommandOutput> { |
| 70 | let lastError: unknown |
| 71 | for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) { |
| 72 | try { |
| 73 | return await client.send(new GetSecretValueCommand({ SecretId: secretId }), { |
| 74 | abortSignal: AbortSignal.timeout(REQUEST_TIMEOUT_MS), |
| 75 | }) |
| 76 | } catch (error) { |
| 77 | lastError = error |
| 78 | if (attempt < MAX_ATTEMPTS) { |
| 79 | const delay = backoffWithJitter(attempt, null, { baseMs: 200, maxMs: 2000 }) |
| 80 | logger.warn( |
| 81 | `Failed to fetch runtime secrets (attempt ${attempt}/${MAX_ATTEMPTS}), retrying`, |
| 82 | { error: getErrorMessage(error) } |
| 83 | ) |
| 84 | await sleep(delay) |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | throw new Error(`Failed to fetch runtime secrets from ${secretId}: ${getErrorMessage(lastError)}`) |
| 89 | } |
| 90 | |
| 91 | function parseSecretJson(secretString: string): Record<string, unknown> { |
| 92 | let parsed: unknown |
no test coverage detected