-
Notifications
You must be signed in to change notification settings - Fork 581
/
waitForFunctionUpdatedV2.ts
64 lines (62 loc) · 2.46 KB
/
waitForFunctionUpdatedV2.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// smithy-typescript generated code
import { checkExceptions, createWaiter, WaiterConfiguration, WaiterResult, WaiterState } from "@smithy/util-waiter";
import { GetFunctionCommand, GetFunctionCommandInput } from "../commands/GetFunctionCommand";
import { LambdaClient } from "../LambdaClient";
const checkState = async (client: LambdaClient, input: GetFunctionCommandInput): Promise<WaiterResult> => {
let reason;
try {
const result: any = await client.send(new GetFunctionCommand(input));
reason = result;
try {
const returnComparator = () => {
return result.Configuration.LastUpdateStatus;
};
if (returnComparator() === "Successful") {
return { state: WaiterState.SUCCESS, reason };
}
} catch (e) {}
try {
const returnComparator = () => {
return result.Configuration.LastUpdateStatus;
};
if (returnComparator() === "Failed") {
return { state: WaiterState.FAILURE, reason };
}
} catch (e) {}
try {
const returnComparator = () => {
return result.Configuration.LastUpdateStatus;
};
if (returnComparator() === "InProgress") {
return { state: WaiterState.RETRY, reason };
}
} catch (e) {}
} catch (exception) {
reason = exception;
}
return { state: WaiterState.RETRY, reason };
};
/**
* Waits for the function's LastUpdateStatus to be Successful. This waiter uses GetFunction API. This should be used after function updates.
* @deprecated Use waitUntilFunctionUpdatedV2 instead. waitForFunctionUpdatedV2 does not throw error in non-success cases.
*/
export const waitForFunctionUpdatedV2 = async (
params: WaiterConfiguration<LambdaClient>,
input: GetFunctionCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 1, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
* Waits for the function's LastUpdateStatus to be Successful. This waiter uses GetFunction API. This should be used after function updates.
* @param params - Waiter configuration options.
* @param input - The input to GetFunctionCommand for polling.
*/
export const waitUntilFunctionUpdatedV2 = async (
params: WaiterConfiguration<LambdaClient>,
input: GetFunctionCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 1, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};