UNPKG

6.05 kBTypeScriptView Raw
1import { Construct } from 'constructs';
2import { Duration } from '../duration';
3import { Size } from '../size';
4import { Construct as CoreConstruct } from '../construct-compat';
5/**
6 * Initialization properties for `CustomResourceProvider`.
7 *
8 */
9export interface CustomResourceProviderProps {
10 /**
11 * A local file system directory with the provider's code. The code will be
12 * bundled into a zip asset and wired to the provider's AWS Lambda function.
13 */
14 readonly codeDirectory: string;
15 /**
16 * The AWS Lambda runtime and version to use for the provider.
17 */
18 readonly runtime: CustomResourceProviderRuntime;
19 /**
20 * A set of IAM policy statements to include in the inline policy of the
21 * provider's lambda function.
22 *
23 * **Please note**: these are direct IAM JSON policy blobs, *not* `iam.PolicyStatement`
24 * objects like you will see in the rest of the CDK.
25 *
26 * @default - no additional inline policy
27 *
28 * @example
29 * const provider = CustomResourceProvider.getOrCreateProvider(this, 'Custom::MyCustomResourceType', {
30 * codeDirectory: `${__dirname}/my-handler`,
31 * runtime: CustomResourceProviderRuntime.NODEJS_14_X,
32 * policyStatements: [
33 * {
34 * Effect: 'Allow',
35 * Action: 's3:PutObject*',
36 * Resource: '*',
37 * }
38 * ],
39 * });
40 */
41 readonly policyStatements?: any[];
42 /**
43 * AWS Lambda timeout for the provider.
44 *
45 * @default Duration.minutes(15)
46 */
47 readonly timeout?: Duration;
48 /**
49 * The amount of memory that your function has access to. Increasing the
50 * function's memory also increases its CPU allocation.
51 *
52 * @default Size.mebibytes(128)
53 */
54 readonly memorySize?: Size;
55 /**
56 * Key-value pairs that are passed to Lambda as Environment
57 *
58 * @default - No environment variables.
59 */
60 readonly environment?: {
61 [key: string]: string;
62 };
63 /**
64 * A description of the function.
65 *
66 * @default - No description.
67 */
68 readonly description?: string;
69}
70/**
71 * The lambda runtime to use for the resource provider. This also indicates
72 * which language is used for the handler.
73 */
74export declare enum CustomResourceProviderRuntime {
75 /**
76 * Node.js 12.x
77 *
78 * @deprecated Use {@link NODEJS_14_X}
79 */
80 NODEJS_12 = "deprecated_nodejs12.x",
81 /**
82 * Node.js 12.x
83 */
84 NODEJS_12_X = "nodejs12.x",
85 /**
86 * Node.js 14.x
87 */
88 NODEJS_14_X = "nodejs14.x",
89 /**
90 * Node.js 16.x
91 */
92 NODEJS_16_X = "nodejs16.x"
93}
94/**
95 * An AWS-Lambda backed custom resource provider, for CDK Construct Library constructs
96 *
97 * This is a provider for `CustomResource` constructs, backed by an AWS Lambda
98 * Function. It only supports NodeJS runtimes.
99 *
100 * **This is not a generic custom resource provider class**. It is specifically
101 * intended to be used only by constructs in the AWS CDK Construct Library, and
102 * only exists here because of reverse dependency issues (for example, it cannot
103 * use `iam.PolicyStatement` objects, since the `iam` library already depends on
104 * the CDK `core` library and we cannot have cyclic dependencies).
105 *
106 * If you are not writing constructs for the AWS Construct Library, you should
107 * use the `Provider` class in the `custom-resources` module instead, which has
108 * a better API and supports all Lambda runtimes, not just Node.
109 *
110 * N.B.: When you are writing Custom Resource Providers, there are a number of
111 * lifecycle events you have to pay attention to. These are documented in the
112 * README of the `custom-resources` module. Be sure to give the documentation
113 * in that module a read, regardless of whether you end up using the Provider
114 * class in there or this one.
115 */
116export declare class CustomResourceProvider extends CoreConstruct {
117 /**
118 * Returns a stack-level singleton ARN (service token) for the custom resource
119 * provider.
120 *
121 * @param scope Construct scope
122 * @param uniqueid A globally unique id that will be used for the stack-level
123 * construct.
124 * @param props Provider properties which will only be applied when the
125 * provider is first created.
126 * @returns the service token of the custom resource provider, which should be
127 * used when defining a `CustomResource`.
128 */
129 static getOrCreate(scope: Construct, uniqueid: string, props: CustomResourceProviderProps): string;
130 /**
131 * Returns a stack-level singleton for the custom resource provider.
132 *
133 * @param scope Construct scope
134 * @param uniqueid A globally unique id that will be used for the stack-level
135 * construct.
136 * @param props Provider properties which will only be applied when the
137 * provider is first created.
138 * @returns the service token of the custom resource provider, which should be
139 * used when defining a `CustomResource`.
140 */
141 static getOrCreateProvider(scope: Construct, uniqueid: string, props: CustomResourceProviderProps): CustomResourceProvider;
142 /**
143 * The ARN of the provider's AWS Lambda function which should be used as the
144 * `serviceToken` when defining a custom resource.
145 *
146 * @example
147 * declare const myProvider: CustomResourceProvider;
148 *
149 * new CustomResource(this, 'MyCustomResource', {
150 * serviceToken: myProvider.serviceToken,
151 * properties: {
152 * myPropertyOne: 'one',
153 * myPropertyTwo: 'two',
154 * },
155 * });
156 */
157 readonly serviceToken: string;
158 /**
159 * The ARN of the provider's AWS Lambda function role.
160 */
161 readonly roleArn: string;
162 /**
163 * The hash of the lambda code backing this provider. Can be used to trigger updates
164 * on code changes, even when the properties of a custom resource remain unchanged.
165 */
166 readonly codeHash: string;
167 protected constructor(scope: Construct, id: string, props: CustomResourceProviderProps);
168 private renderEnvironmentVariables;
169}