-
Notifications
You must be signed in to change notification settings - Fork 581
/
waitForFunctionUpdated.ts
67 lines (65 loc) · 2.54 KB
/
waitForFunctionUpdated.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
65
66
67
// smithy-typescript generated code
import { checkExceptions, createWaiter, WaiterConfiguration, WaiterResult, WaiterState } from "@smithy/util-waiter";
import {
GetFunctionConfigurationCommand,
GetFunctionConfigurationCommandInput,
} from "../commands/GetFunctionConfigurationCommand";
import { LambdaClient } from "../LambdaClient";
const checkState = async (client: LambdaClient, input: GetFunctionConfigurationCommandInput): Promise<WaiterResult> => {
let reason;
try {
const result: any = await client.send(new GetFunctionConfigurationCommand(input));
reason = result;
try {
const returnComparator = () => {
return result.LastUpdateStatus;
};
if (returnComparator() === "Successful") {
return { state: WaiterState.SUCCESS, reason };
}
} catch (e) {}
try {
const returnComparator = () => {
return result.LastUpdateStatus;
};
if (returnComparator() === "Failed") {
return { state: WaiterState.FAILURE, reason };
}
} catch (e) {}
try {
const returnComparator = () => {
return result.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 GetFunctionConfiguration API. This should be used after function updates.
* @deprecated Use waitUntilFunctionUpdated instead. waitForFunctionUpdated does not throw error in non-success cases.
*/
export const waitForFunctionUpdated = async (
params: WaiterConfiguration<LambdaClient>,
input: GetFunctionConfigurationCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 5, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
* Waits for the function's LastUpdateStatus to be Successful. This waiter uses GetFunctionConfiguration API. This should be used after function updates.
* @param params - Waiter configuration options.
* @param input - The input to GetFunctionConfigurationCommand for polling.
*/
export const waitUntilFunctionUpdated = async (
params: WaiterConfiguration<LambdaClient>,
input: GetFunctionConfigurationCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 5, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};