Skip to content

Commit 61bf548

Browse files
authored
HookStack: Increase AWS SDK retries (#95)
I was initially looking at the adaptive strategy or a custom backoff function, but I think this should be fine to begin with. The hook has logic to try to short circuit if this all takes too long. - https://docs.aws.amazon.com/sdkref/latest/guide/feature-retry-behavior.html - https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-smithy-util-retry/ - https://github.com/seek-oss/aws-codedeploy-hooks/blob/714756b69539717fd25f4420c893f29f9b7fc317/packages/infra/src/handlers/index.ts#L20
1 parent 714756b commit 61bf548

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

.changeset/cold-adults-ring.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@seek/aws-codedeploy-infra': patch
3+
---
4+
5+
HookStack: Increase AWS SDK retries

packages/infra/src/handlers/framework/aws.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
import { CodeDeployClient } from '@aws-sdk/client-codedeploy';
2-
import { LambdaClient } from '@aws-sdk/client-lambda';
1+
import {
2+
CodeDeployClient,
3+
type CodeDeployClientConfig,
4+
} from '@aws-sdk/client-codedeploy';
5+
import { LambdaClient, type LambdaClientConfig } from '@aws-sdk/client-lambda';
36

47
import { config } from '../config';
58

69
const clientConfig = {
7-
maxAttempts: 5,
10+
maxAttempts: 8,
811
region: config.region,
9-
};
12+
} satisfies CodeDeployClientConfig & LambdaClientConfig;
1013

1114
export const codeDeployClient = new CodeDeployClient(clientConfig);
1215

packages/infra/src/handlers/process/lambda/prune.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {
22
type AliasConfiguration,
33
DeleteFunctionCommand,
44
type FunctionConfiguration,
5-
LambdaClient,
65
ListAliasesCommand,
76
ListVersionsByFunctionCommand,
87
} from '@aws-sdk/client-lambda';
98
import { Env } from 'skuba-dive';
109

10+
import { lambdaClient } from '../../framework/aws';
1111
import { getContext } from '../../framework/context';
1212
import { logger } from '../../framework/logging';
1313

@@ -17,8 +17,6 @@ type Args = Pick<LambdaFunction, 'name'>;
1717

1818
const MAX_DELETIONS_PER_RUN = 20;
1919

20-
const lambda = new LambdaClient();
21-
2220
export const prune = async (fns: Args[]): Promise<void> => {
2321
await Promise.all(fns.map((fn) => pruneFunction(fn)));
2422
};
@@ -62,7 +60,7 @@ export const pruneFunction = async ({ name }: Args): Promise<void> => {
6260

6361
await Promise.all(
6462
versionsToPrune.map((version) =>
65-
lambda.send(
63+
lambdaClient.send(
6664
new DeleteFunctionCommand({
6765
FunctionName: version.FunctionName,
6866
Qualifier: version.Version,
@@ -78,7 +76,7 @@ const listLambdaVersions = async (
7876
abortSignal?: AbortSignal,
7977
marker?: string,
8078
): Promise<FunctionConfiguration[]> => {
81-
const result = await lambda.send(
79+
const result = await lambdaClient.send(
8280
new ListVersionsByFunctionCommand({
8381
FunctionName: functionName,
8482
Marker: marker,
@@ -105,7 +103,7 @@ const listAliases = async (
105103
abortSignal?: AbortSignal,
106104
marker?: string,
107105
): Promise<AliasConfiguration[]> => {
108-
const result = await lambda.send(
106+
const result = await lambdaClient.send(
109107
new ListAliasesCommand({
110108
FunctionName: functionName,
111109
Marker: marker,

0 commit comments

Comments
 (0)