1 | // this is a type definition file that exports ambiant types that can be used
|
2 | // to implement async custom resource handler and enjoy the comfort of type safety.
|
3 |
|
4 | /**
|
5 | * these types can be accessed without needing to `import` the module.
|
6 | * e.g. `AWSCDKAsyncCustomResource.OnEventRequest`
|
7 | */
|
8 | export as namespace AWSCDKAsyncCustomResource;
|
9 |
|
10 | /**
|
11 | * Signature for the `onEvent` handler, which is called when a lifecycle event occurs.
|
12 | */
|
13 | export type OnEventHandler = (event: OnEventRequest) => Promise<OnEventResponse | undefined>;
|
14 |
|
15 | /**
|
16 | * Signature for the `isComplete` handler, which is called to detemrine if the
|
17 | * event handling is complete. As long as this method returns `IsComplete:
|
18 | * false`, the handler will be called (based on the rety policy defined by the
|
19 | * provider) until a timeout occurs, an error is thrown or until it returns
|
20 | * `true`.
|
21 | */
|
22 | export type IsCompleteHandler = (event: IsCompleteRequest) => Promise<IsCompleteResponse>;
|
23 |
|
24 | /**
|
25 | * The object passed to the user-defined `onEvent` handler.
|
26 | */
|
27 | export interface OnEventRequest extends AWSLambda.CloudFormationCustomResourceEventCommon {
|
28 | /**
|
29 | * The request type is set by the AWS CloudFormation stack operation
|
30 | * (create-stack, update-stack, or delete-stack) that was initiated by the
|
31 | * template developer for the stack that contains the custom resource.
|
32 | */
|
33 | readonly RequestType: 'Create' | 'Update' | 'Delete';
|
34 |
|
35 | /**
|
36 | * Used only for Update requests. Contains the resource properties that were
|
37 | * declared previous to the update request.
|
38 | */
|
39 | readonly OldResourceProperties?: { [key: string]: any };
|
40 |
|
41 | /**
|
42 | * A required custom resource provider-defined physical ID that is unique for
|
43 | * that provider.
|
44 | *
|
45 | * Always sent with 'Update' and 'Delete' requests; never sent with 'Create'.
|
46 | */
|
47 | readonly PhysicalResourceId?: string;
|
48 | }
|
49 |
|
50 | /**
|
51 | * The object returned from the user-defined `onEvent` handler.
|
52 | */
|
53 | interface OnEventResponse {
|
54 | /**
|
55 | * A required custom resource provider-defined physical ID that is unique for
|
56 | * that provider.
|
57 | *
|
58 | * In order to reduce the chance for mistakes, all event types MUST return
|
59 | * with `PhysicalResourceId`.
|
60 | *
|
61 | * - For `Create`, this will be the user-defined or generated physical
|
62 | * resource ID.
|
63 | * - For `Update`, if the returned PhysicalResourceId is different value from
|
64 | * the current one, it means that the old physical resource needs to be
|
65 | * deleted, and CloudFormation will immediately send a `Delete` event with
|
66 | * the old physical ID.
|
67 | * - For `Delete`, this must be the same value received in the event.
|
68 | *
|
69 | * @default - for "Create" requests, defaults to the event's RequestId, for
|
70 | * "Update" and "Delete", defaults to the current `PhysicalResourceId`.
|
71 | */
|
72 | readonly PhysicalResourceId?: string;
|
73 |
|
74 | /**
|
75 | * Resource attributes to return.
|
76 | */
|
77 | readonly Data?: { [name: string]: any };
|
78 |
|
79 | /**
|
80 | * Custom fields returned from OnEvent will be passed to IsComplete.
|
81 | */
|
82 | readonly [key: string]: any;
|
83 |
|
84 | /**
|
85 | * Whether to mask the output of the custom resource when retrieved
|
86 | * by using the `Fn::GetAtt` function. If set to `true`, all returned
|
87 | * values are masked with asterisks (*****).
|
88 | *
|
89 | * @default false
|
90 | */
|
91 | readonly NoEcho?: boolean;
|
92 | }
|
93 |
|
94 | /**
|
95 | * The input to the `isComplete` user defined handler.
|
96 | */
|
97 | export type IsCompleteRequest = OnEventRequest & OnEventResponse;
|
98 |
|
99 | /**
|
100 | * The output of the `isComplete` user-defined handler.
|
101 | */
|
102 | export interface IsCompleteResponse {
|
103 | /**
|
104 | * Indicates if the resource operation is complete or should we retry.
|
105 | */
|
106 | readonly IsComplete: boolean;
|
107 |
|
108 | /**
|
109 | * If present, overrides the PhysicalResourceId of OnEventResponse with the PhysicalResourceId of IsCompleteResponse.
|
110 | */
|
111 | readonly PhysicalResourceId?: string;
|
112 |
|
113 | /**
|
114 | * Additional/changes to resource attributes. This hash will be merged with the one returned from `OnEventResponse`.
|
115 | */
|
116 | readonly Data?: { [name: string]: any };
|
117 | }
|