UNPKG

13.6 kBTypeScriptView Raw
1import * as ecr from '@aws-cdk/aws-ecr';
2import * as ecr_assets from '@aws-cdk/aws-ecr-assets';
3import * as s3 from '@aws-cdk/aws-s3';
4import * as s3_assets from '@aws-cdk/aws-s3-assets';
5import * as cdk from '@aws-cdk/core';
6import { Construct } from '@aws-cdk/core';
7/**
8 * Represents the Lambda Handler Code.
9 */
10export declare abstract class Code {
11 /**
12 * Lambda handler code as an S3 object.
13 * @param bucket The S3 bucket
14 * @param key The object key
15 * @param objectVersion Optional S3 object version
16 */
17 static fromBucket(bucket: s3.IBucket, key: string, objectVersion?: string): S3Code;
18 /**
19 * DEPRECATED
20 * @deprecated use `fromBucket`
21 */
22 static bucket(bucket: s3.IBucket, key: string, objectVersion?: string): S3Code;
23 /**
24 * Inline code for Lambda handler
25 * @returns `LambdaInlineCode` with inline code.
26 * @param code The actual handler code (limited to 4KiB)
27 */
28 static fromInline(code: string): InlineCode;
29 /**
30 * DEPRECATED
31 * @deprecated use `fromInline`
32 */
33 static inline(code: string): InlineCode;
34 /**
35 * Loads the function code from a local disk path.
36 *
37 * @param path Either a directory with the Lambda code bundle or a .zip file
38 */
39 static fromAsset(path: string, options?: s3_assets.AssetOptions): AssetCode;
40 /**
41 * Loads the function code from an asset created by a Docker build.
42 *
43 * By default, the asset is expected to be located at `/asset` in the
44 * image.
45 *
46 * @param path The path to the directory containing the Docker file
47 * @param options Docker build options
48 */
49 static fromDockerBuild(path: string, options?: DockerBuildAssetOptions): AssetCode;
50 /**
51 * DEPRECATED
52 * @deprecated use `fromAsset`
53 */
54 static asset(path: string): AssetCode;
55 /**
56 * Creates a new Lambda source defined using CloudFormation parameters.
57 *
58 * @returns a new instance of `CfnParametersCode`
59 * @param props optional construction properties of {@link CfnParametersCode}
60 */
61 static fromCfnParameters(props?: CfnParametersCodeProps): CfnParametersCode;
62 /**
63 * DEPRECATED
64 * @deprecated use `fromCfnParameters`
65 */
66 static cfnParameters(props?: CfnParametersCodeProps): CfnParametersCode;
67 /**
68 * Use an existing ECR image as the Lambda code.
69 * @param repository the ECR repository that the image is in
70 * @param props properties to further configure the selected image
71 */
72 static fromEcrImage(repository: ecr.IRepository, props?: EcrImageCodeProps): EcrImageCode;
73 /**
74 * Create an ECR image from the specified asset and bind it as the Lambda code.
75 * @param directory the directory from which the asset must be created
76 * @param props properties to further configure the selected image
77 */
78 static fromAssetImage(directory: string, props?: AssetImageCodeProps): AssetImageCode;
79 /**
80 * Determines whether this Code is inline code or not.
81 *
82 * @deprecated this value is ignored since inline is now determined based on the
83 * the `inlineCode` field of `CodeConfig` returned from `bind()`.
84 */
85 abstract readonly isInline: boolean;
86 /**
87 * Called when the lambda or layer is initialized to allow this object to bind
88 * to the stack, add resources and have fun.
89 *
90 * @param scope The binding scope. Don't be smart about trying to down-cast or
91 * assume it's initialized. You may just use it as a construct scope.
92 */
93 abstract bind(scope: Construct): CodeConfig;
94 /**
95 * Called after the CFN function resource has been created to allow the code
96 * class to bind to it. Specifically it's required to allow assets to add
97 * metadata for tooling like SAM CLI to be able to find their origins.
98 */
99 bindToResource(_resource: cdk.CfnResource, _options?: ResourceBindOptions): void;
100}
101/**
102 * Result of binding `Code` into a `Function`.
103 */
104export interface CodeConfig {
105 /**
106 * The location of the code in S3 (mutually exclusive with `inlineCode` and `image`).
107 * @default - code is not an s3 location
108 */
109 readonly s3Location?: s3.Location;
110 /**
111 * Inline code (mutually exclusive with `s3Location` and `image`).
112 * @default - code is not inline code
113 */
114 readonly inlineCode?: string;
115 /**
116 * Docker image configuration (mutually exclusive with `s3Location` and `inlineCode`).
117 * @default - code is not an ECR container image
118 */
119 readonly image?: CodeImageConfig;
120}
121/**
122 * Result of the bind when an ECR image is used.
123 */
124export interface CodeImageConfig {
125 /**
126 * URI to the Docker image.
127 */
128 readonly imageUri: string;
129 /**
130 * Specify or override the CMD on the specified Docker image or Dockerfile.
131 * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
132 * @see https://docs.docker.com/engine/reference/builder/#cmd
133 * @default - use the CMD specified in the docker image or Dockerfile.
134 */
135 readonly cmd?: string[];
136 /**
137 * Specify or override the ENTRYPOINT on the specified Docker image or Dockerfile.
138 * An ENTRYPOINT allows you to configure a container that will run as an executable.
139 * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
140 * @see https://docs.docker.com/engine/reference/builder/#entrypoint
141 * @default - use the ENTRYPOINT in the docker image or Dockerfile.
142 */
143 readonly entrypoint?: string[];
144 /**
145 * Specify or override the WORKDIR on the specified Docker image or Dockerfile.
146 * A WORKDIR allows you to configure the working directory the container will use.
147 * @see https://docs.docker.com/engine/reference/builder/#workdir
148 * @default - use the WORKDIR in the docker image or Dockerfile.
149 */
150 readonly workingDirectory?: string;
151}
152/**
153 * Lambda code from an S3 archive.
154 */
155export declare class S3Code extends Code {
156 private key;
157 private objectVersion?;
158 readonly isInline = false;
159 private bucketName;
160 constructor(bucket: s3.IBucket, key: string, objectVersion?: string | undefined);
161 bind(_scope: Construct): CodeConfig;
162}
163/**
164 * Lambda code from an inline string (limited to 4KiB).
165 */
166export declare class InlineCode extends Code {
167 private code;
168 readonly isInline = true;
169 constructor(code: string);
170 bind(_scope: Construct): CodeConfig;
171}
172/**
173 * Lambda code from a local directory.
174 */
175export declare class AssetCode extends Code {
176 readonly path: string;
177 private readonly options;
178 readonly isInline = false;
179 private asset?;
180 /**
181 * @param path The path to the asset file or directory.
182 */
183 constructor(path: string, options?: s3_assets.AssetOptions);
184 bind(scope: Construct): CodeConfig;
185 bindToResource(resource: cdk.CfnResource, options?: ResourceBindOptions): void;
186}
187export interface ResourceBindOptions {
188 /**
189 * The name of the CloudFormation property to annotate with asset metadata.
190 * @see https://github.com/aws/aws-cdk/issues/1432
191 * @default Code
192 */
193 readonly resourceProperty?: string;
194}
195/**
196 * Construction properties for {@link CfnParametersCode}.
197 */
198export interface CfnParametersCodeProps {
199 /**
200 * The CloudFormation parameter that represents the name of the S3 Bucket
201 * where the Lambda code will be located in.
202 * Must be of type 'String'.
203 *
204 * @default a new parameter will be created
205 */
206 readonly bucketNameParam?: cdk.CfnParameter;
207 /**
208 * The CloudFormation parameter that represents the path inside the S3 Bucket
209 * where the Lambda code will be located at.
210 * Must be of type 'String'.
211 *
212 * @default a new parameter will be created
213 */
214 readonly objectKeyParam?: cdk.CfnParameter;
215}
216/**
217 * Lambda code defined using 2 CloudFormation parameters.
218 * Useful when you don't have access to the code of your Lambda from your CDK code, so you can't use Assets,
219 * and you want to deploy the Lambda in a CodePipeline, using CloudFormation Actions -
220 * you can fill the parameters using the {@link #assign} method.
221 */
222export declare class CfnParametersCode extends Code {
223 readonly isInline = false;
224 private _bucketNameParam?;
225 private _objectKeyParam?;
226 constructor(props?: CfnParametersCodeProps);
227 bind(scope: Construct): CodeConfig;
228 /**
229 * Create a parameters map from this instance's CloudFormation parameters.
230 *
231 * It returns a map with 2 keys that correspond to the names of the parameters defined in this Lambda code,
232 * and as values it contains the appropriate expressions pointing at the provided S3 location
233 * (most likely, obtained from a CodePipeline Artifact by calling the `artifact.s3Location` method).
234 * The result should be provided to the CloudFormation Action
235 * that is deploying the Stack that the Lambda with this code is part of,
236 * in the `parameterOverrides` property.
237 *
238 * @param location the location of the object in S3 that represents the Lambda code
239 */
240 assign(location: s3.Location): {
241 [name: string]: any;
242 };
243 get bucketNameParam(): string;
244 get objectKeyParam(): string;
245}
246/**
247 * Properties to initialize a new EcrImageCode
248 */
249export interface EcrImageCodeProps {
250 /**
251 * Specify or override the CMD on the specified Docker image or Dockerfile.
252 * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
253 * @see https://docs.docker.com/engine/reference/builder/#cmd
254 * @default - use the CMD specified in the docker image or Dockerfile.
255 */
256 readonly cmd?: string[];
257 /**
258 * Specify or override the ENTRYPOINT on the specified Docker image or Dockerfile.
259 * An ENTRYPOINT allows you to configure a container that will run as an executable.
260 * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
261 * @see https://docs.docker.com/engine/reference/builder/#entrypoint
262 * @default - use the ENTRYPOINT in the docker image or Dockerfile.
263 */
264 readonly entrypoint?: string[];
265 /**
266 * Specify or override the WORKDIR on the specified Docker image or Dockerfile.
267 * A WORKDIR allows you to configure the working directory the container will use.
268 * @see https://docs.docker.com/engine/reference/builder/#workdir
269 * @default - use the WORKDIR in the docker image or Dockerfile.
270 */
271 readonly workingDirectory?: string;
272 /**
273 * The image tag to use when pulling the image from ECR.
274 * @default 'latest'
275 * @deprecated use `tagOrDigest`
276 */
277 readonly tag?: string;
278 /**
279 * The image tag or digest to use when pulling the image from ECR (digests must start with `sha256:`).
280 * @default 'latest'
281 */
282 readonly tagOrDigest?: string;
283}
284/**
285 * Represents a Docker image in ECR that can be bound as Lambda Code.
286 */
287export declare class EcrImageCode extends Code {
288 private readonly repository;
289 private readonly props;
290 readonly isInline: boolean;
291 constructor(repository: ecr.IRepository, props?: EcrImageCodeProps);
292 bind(_: Construct): CodeConfig;
293}
294/**
295 * Properties to initialize a new AssetImage
296 */
297export interface AssetImageCodeProps extends ecr_assets.DockerImageAssetOptions {
298 /**
299 * Specify or override the CMD on the specified Docker image or Dockerfile.
300 * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
301 * @see https://docs.docker.com/engine/reference/builder/#cmd
302 * @default - use the CMD specified in the docker image or Dockerfile.
303 */
304 readonly cmd?: string[];
305 /**
306 * Specify or override the ENTRYPOINT on the specified Docker image or Dockerfile.
307 * An ENTRYPOINT allows you to configure a container that will run as an executable.
308 * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
309 * @see https://docs.docker.com/engine/reference/builder/#entrypoint
310 * @default - use the ENTRYPOINT in the docker image or Dockerfile.
311 */
312 readonly entrypoint?: string[];
313 /**
314 * Specify or override the WORKDIR on the specified Docker image or Dockerfile.
315 * A WORKDIR allows you to configure the working directory the container will use.
316 * @see https://docs.docker.com/engine/reference/builder/#workdir
317 * @default - use the WORKDIR in the docker image or Dockerfile.
318 */
319 readonly workingDirectory?: string;
320}
321/**
322 * Represents an ECR image that will be constructed from the specified asset and can be bound as Lambda code.
323 */
324export declare class AssetImageCode extends Code {
325 private readonly directory;
326 private readonly props;
327 readonly isInline: boolean;
328 private asset?;
329 constructor(directory: string, props: AssetImageCodeProps);
330 bind(scope: Construct): CodeConfig;
331 bindToResource(resource: cdk.CfnResource, options?: ResourceBindOptions): void;
332}
333/**
334 * Options when creating an asset from a Docker build.
335 */
336export interface DockerBuildAssetOptions extends cdk.DockerBuildOptions {
337 /**
338 * The path in the Docker image where the asset is located after the build
339 * operation.
340 *
341 * @default /asset
342 */
343 readonly imagePath?: string;
344 /**
345 * The path on the local filesystem where the asset will be copied
346 * using `docker cp`.
347 *
348 * @default - a unique temporary directory in the system temp directory
349 */
350 readonly outputPath?: string;
351}