code.d.ts
  1  import * as ecr from '@aws-cdk/aws-ecr';
  2  import * as ecr_assets from '@aws-cdk/aws-ecr-assets';
  3  import * as s3 from '@aws-cdk/aws-s3';
  4  import * as s3_assets from '@aws-cdk/aws-s3-assets';
  5  import * as cdk from '@aws-cdk/core';
  6  import { Construct } from '@aws-cdk/core';
  7  /**
  8   * Represents the Lambda Handler Code.
  9   *
 10   * @stability stable
 11   */
 12  export declare abstract class Code {
 13      /**
 14       * Lambda handler code as an S3 object.
 15       *
 16       * @param bucket The S3 bucket.
 17       * @param key The object key.
 18       * @param objectVersion Optional S3 object version.
 19       * @stability stable
 20       */
 21      static fromBucket(bucket: s3.IBucket, key: string, objectVersion?: string): S3Code;
 22      /**
 23       * (deprecated) DEPRECATED.
 24       *
 25       * @deprecated use `fromBucket`
 26       */
 27      static bucket(bucket: s3.IBucket, key: string, objectVersion?: string): S3Code;
 28      /**
 29       * Inline code for Lambda handler.
 30       *
 31       * @param code The actual handler code (limited to 4KiB).
 32       * @returns `LambdaInlineCode` with inline code.
 33       * @stability stable
 34       */
 35      static fromInline(code: string): InlineCode;
 36      /**
 37       * (deprecated) DEPRECATED.
 38       *
 39       * @deprecated use `fromInline`
 40       */
 41      static inline(code: string): InlineCode;
 42      /**
 43       * Loads the function code from a local disk path.
 44       *
 45       * @param path Either a directory with the Lambda code bundle or a .zip file.
 46       * @stability stable
 47       */
 48      static fromAsset(path: string, options?: s3_assets.AssetOptions): AssetCode;
 49      /**
 50       * Loads the function code from an asset created by a Docker build.
 51       *
 52       * By default, the asset is expected to be located at `/asset` in the
 53       * image.
 54       *
 55       * @param path The path to the directory containing the Docker file.
 56       * @param options Docker build options.
 57       * @stability stable
 58       */
 59      static fromDockerBuild(path: string, options?: DockerBuildAssetOptions): AssetCode;
 60      /**
 61       * (deprecated) DEPRECATED.
 62       *
 63       * @deprecated use `fromAsset`
 64       */
 65      static asset(path: string): AssetCode;
 66      /**
 67       * Creates a new Lambda source defined using CloudFormation parameters.
 68       *
 69       * @param props optional construction properties of {@link CfnParametersCode}.
 70       * @returns a new instance of `CfnParametersCode`
 71       * @stability stable
 72       */
 73      static fromCfnParameters(props?: CfnParametersCodeProps): CfnParametersCode;
 74      /**
 75       * (deprecated) DEPRECATED.
 76       *
 77       * @deprecated use `fromCfnParameters`
 78       */
 79      static cfnParameters(props?: CfnParametersCodeProps): CfnParametersCode;
 80      /**
 81       * Use an existing ECR image as the Lambda code.
 82       *
 83       * @param repository the ECR repository that the image is in.
 84       * @param props properties to further configure the selected image.
 85       * @stability stable
 86       */
 87      static fromEcrImage(repository: ecr.IRepository, props?: EcrImageCodeProps): EcrImageCode;
 88      /**
 89       * Create an ECR image from the specified asset and bind it as the Lambda code.
 90       *
 91       * @param directory the directory from which the asset must be created.
 92       * @param props properties to further configure the selected image.
 93       * @stability stable
 94       */
 95      static fromAssetImage(directory: string, props?: AssetImageCodeProps): AssetImageCode;
 96      /**
 97       * (deprecated) Determines whether this Code is inline code or not.
 98       *
 99       * @deprecated this value is ignored since inline is now determined based on the
100       * the `inlineCode` field of `CodeConfig` returned from `bind()`.
101       */
102      abstract readonly isInline: boolean;
103      /**
104       * Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
105       *
106       * @param scope The binding scope.
107       * @stability stable
108       */
109      abstract bind(scope: Construct): CodeConfig;
110      /**
111       * Called after the CFN function resource has been created to allow the code class to bind to it.
112       *
113       * Specifically it's required to allow assets to add
114       * metadata for tooling like SAM CLI to be able to find their origins.
115       *
116       * @stability stable
117       */
118      bindToResource(_resource: cdk.CfnResource, _options?: ResourceBindOptions): void;
119  }
120  /**
121   * Result of binding `Code` into a `Function`.
122   *
123   * @stability stable
124   */
125  export interface CodeConfig {
126      /**
127       * The location of the code in S3 (mutually exclusive with `inlineCode` and `image`).
128       *
129       * @default - code is not an s3 location
130       * @stability stable
131       */
132      readonly s3Location?: s3.Location;
133      /**
134       * Inline code (mutually exclusive with `s3Location` and `image`).
135       *
136       * @default - code is not inline code
137       * @stability stable
138       */
139      readonly inlineCode?: string;
140      /**
141       * Docker image configuration (mutually exclusive with `s3Location` and `inlineCode`).
142       *
143       * @default - code is not an ECR container image
144       * @stability stable
145       */
146      readonly image?: CodeImageConfig;
147  }
148  /**
149   * Result of the bind when an ECR image is used.
150   *
151   * @stability stable
152   */
153  export interface CodeImageConfig {
154      /**
155       * URI to the Docker image.
156       *
157       * @stability stable
158       */
159      readonly imageUri: string;
160      /**
161       * Specify or override the CMD on the specified Docker image or Dockerfile.
162       *
163       * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
164       *
165       * @default - use the CMD specified in the docker image or Dockerfile.
166       * @see https://docs.docker.com/engine/reference/builder/#cmd
167       * @stability stable
168       */
169      readonly cmd?: string[];
170      /**
171       * Specify or override the ENTRYPOINT on the specified Docker image or Dockerfile.
172       *
173       * An ENTRYPOINT allows you to configure a container that will run as an executable.
174       * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
175       *
176       * @default - use the ENTRYPOINT in the docker image or Dockerfile.
177       * @see https://docs.docker.com/engine/reference/builder/#entrypoint
178       * @stability stable
179       */
180      readonly entrypoint?: string[];
181      /**
182       * Specify or override the WORKDIR on the specified Docker image or Dockerfile.
183       *
184       * A WORKDIR allows you to configure the working directory the container will use.
185       *
186       * @default - use the WORKDIR in the docker image or Dockerfile.
187       * @see https://docs.docker.com/engine/reference/builder/#workdir
188       * @stability stable
189       */
190      readonly workingDirectory?: string;
191  }
192  /**
193   * Lambda code from an S3 archive.
194   *
195   * @stability stable
196   */
197  export declare class S3Code extends Code {
198      private key;
199      private objectVersion?;
200      /**
201       * Determines whether this Code is inline code or not.
202       *
203       * @stability stable
204       */
205      readonly isInline = false;
206      private bucketName;
207      /**
208       * @stability stable
209       */
210      constructor(bucket: s3.IBucket, key: string, objectVersion?: string | undefined);
211      /**
212       * Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
213       *
214       * @stability stable
215       */
216      bind(_scope: Construct): CodeConfig;
217  }
218  /**
219   * Lambda code from an inline string (limited to 4KiB).
220   *
221   * @stability stable
222   */
223  export declare class InlineCode extends Code {
224      private code;
225      /**
226       * Determines whether this Code is inline code or not.
227       *
228       * @stability stable
229       */
230      readonly isInline = true;
231      /**
232       * @stability stable
233       */
234      constructor(code: string);
235      /**
236       * Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
237       *
238       * @stability stable
239       */
240      bind(_scope: Construct): CodeConfig;
241  }
242  /**
243   * Lambda code from a local directory.
244   *
245   * @stability stable
246   */
247  export declare class AssetCode extends Code {
248      readonly path: string;
249      private readonly options;
250      /**
251       * Determines whether this Code is inline code or not.
252       *
253       * @stability stable
254       */
255      readonly isInline = false;
256      private asset?;
257      /**
258       * @param path The path to the asset file or directory.
259       * @stability stable
260       */
261      constructor(path: string, options?: s3_assets.AssetOptions);
262      /**
263       * Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
264       *
265       * @stability stable
266       */
267      bind(scope: Construct): CodeConfig;
268      /**
269       * Called after the CFN function resource has been created to allow the code class to bind to it.
270       *
271       * Specifically it's required to allow assets to add
272       * metadata for tooling like SAM CLI to be able to find their origins.
273       *
274       * @stability stable
275       */
276      bindToResource(resource: cdk.CfnResource, options?: ResourceBindOptions): void;
277  }
278  /**
279   * @stability stable
280   */
281  export interface ResourceBindOptions {
282      /**
283       * The name of the CloudFormation property to annotate with asset metadata.
284       *
285       * @default Code
286       * @see https://github.com/aws/aws-cdk/issues/1432
287       * @stability stable
288       */
289      readonly resourceProperty?: string;
290  }
291  /**
292   * Construction properties for {@link CfnParametersCode}.
293   *
294   * @stability stable
295   */
296  export interface CfnParametersCodeProps {
297      /**
298       * The CloudFormation parameter that represents the name of the S3 Bucket where the Lambda code will be located in.
299       *
300       * Must be of type 'String'.
301       *
302       * @default a new parameter will be created
303       * @stability stable
304       */
305      readonly bucketNameParam?: cdk.CfnParameter;
306      /**
307       * The CloudFormation parameter that represents the path inside the S3 Bucket where the Lambda code will be located at.
308       *
309       * Must be of type 'String'.
310       *
311       * @default a new parameter will be created
312       * @stability stable
313       */
314      readonly objectKeyParam?: cdk.CfnParameter;
315  }
316  /**
317   * Lambda code defined using 2 CloudFormation parameters.
318   *
319   * Useful when you don't have access to the code of your Lambda from your CDK code, so you can't use Assets,
320   * and you want to deploy the Lambda in a CodePipeline, using CloudFormation Actions -
321   * you can fill the parameters using the {@link #assign} method.
322   *
323   * @stability stable
324   */
325  export declare class CfnParametersCode extends Code {
326      /**
327       * Determines whether this Code is inline code or not.
328       *
329       * @stability stable
330       */
331      readonly isInline = false;
332      private _bucketNameParam?;
333      private _objectKeyParam?;
334      /**
335       * @stability stable
336       */
337      constructor(props?: CfnParametersCodeProps);
338      /**
339       * Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
340       *
341       * @stability stable
342       */
343      bind(scope: Construct): CodeConfig;
344      /**
345       * Create a parameters map from this instance's CloudFormation parameters.
346       *
347       * It returns a map with 2 keys that correspond to the names of the parameters defined in this Lambda code,
348       * and as values it contains the appropriate expressions pointing at the provided S3 location
349       * (most likely, obtained from a CodePipeline Artifact by calling the `artifact.s3Location` method).
350       * The result should be provided to the CloudFormation Action
351       * that is deploying the Stack that the Lambda with this code is part of,
352       * in the `parameterOverrides` property.
353       *
354       * @param location the location of the object in S3 that represents the Lambda code.
355       * @stability stable
356       */
357      assign(location: s3.Location): {
358          [name: string]: any;
359      };
360      /**
361       * @stability stable
362       */
363      get bucketNameParam(): string;
364      /**
365       * @stability stable
366       */
367      get objectKeyParam(): string;
368  }
369  /**
370   * Properties to initialize a new EcrImageCode.
371   *
372   * @stability stable
373   */
374  export interface EcrImageCodeProps {
375      /**
376       * Specify or override the CMD on the specified Docker image or Dockerfile.
377       *
378       * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
379       *
380       * @default - use the CMD specified in the docker image or Dockerfile.
381       * @see https://docs.docker.com/engine/reference/builder/#cmd
382       * @stability stable
383       */
384      readonly cmd?: string[];
385      /**
386       * Specify or override the ENTRYPOINT on the specified Docker image or Dockerfile.
387       *
388       * An ENTRYPOINT allows you to configure a container that will run as an executable.
389       * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
390       *
391       * @default - use the ENTRYPOINT in the docker image or Dockerfile.
392       * @see https://docs.docker.com/engine/reference/builder/#entrypoint
393       * @stability stable
394       */
395      readonly entrypoint?: string[];
396      /**
397       * Specify or override the WORKDIR on the specified Docker image or Dockerfile.
398       *
399       * A WORKDIR allows you to configure the working directory the container will use.
400       *
401       * @default - use the WORKDIR in the docker image or Dockerfile.
402       * @see https://docs.docker.com/engine/reference/builder/#workdir
403       * @stability stable
404       */
405      readonly workingDirectory?: string;
406      /**
407       * The image tag to use when pulling the image from ECR.
408       *
409       * @default 'latest'
410       * @stability stable
411       */
412      readonly tag?: string;
413  }
414  /**
415   * Represents a Docker image in ECR that can be bound as Lambda Code.
416   *
417   * @stability stable
418   */
419  export declare class EcrImageCode extends Code {
420      private readonly repository;
421      private readonly props;
422      /**
423       * Determines whether this Code is inline code or not.
424       *
425       * @stability stable
426       */
427      readonly isInline: boolean;
428      /**
429       * @stability stable
430       */
431      constructor(repository: ecr.IRepository, props?: EcrImageCodeProps);
432      /**
433       * Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
434       *
435       * @stability stable
436       */
437      bind(_: Construct): CodeConfig;
438  }
439  /**
440   * Properties to initialize a new AssetImage.
441   *
442   * @stability stable
443   */
444  export interface AssetImageCodeProps extends ecr_assets.DockerImageAssetOptions {
445      /**
446       * Specify or override the CMD on the specified Docker image or Dockerfile.
447       *
448       * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
449       *
450       * @default - use the CMD specified in the docker image or Dockerfile.
451       * @see https://docs.docker.com/engine/reference/builder/#cmd
452       * @stability stable
453       */
454      readonly cmd?: string[];
455      /**
456       * Specify or override the ENTRYPOINT on the specified Docker image or Dockerfile.
457       *
458       * An ENTRYPOINT allows you to configure a container that will run as an executable.
459       * This needs to be in the 'exec form', viz., `[ 'executable', 'param1', 'param2' ]`.
460       *
461       * @default - use the ENTRYPOINT in the docker image or Dockerfile.
462       * @see https://docs.docker.com/engine/reference/builder/#entrypoint
463       * @stability stable
464       */
465      readonly entrypoint?: string[];
466      /**
467       * Specify or override the WORKDIR on the specified Docker image or Dockerfile.
468       *
469       * A WORKDIR allows you to configure the working directory the container will use.
470       *
471       * @default - use the WORKDIR in the docker image or Dockerfile.
472       * @see https://docs.docker.com/engine/reference/builder/#workdir
473       * @stability stable
474       */
475      readonly workingDirectory?: string;
476  }
477  /**
478   * Represents an ECR image that will be constructed from the specified asset and can be bound as Lambda code.
479   *
480   * @stability stable
481   */
482  export declare class AssetImageCode extends Code {
483      private readonly directory;
484      private readonly props;
485      /**
486       * Determines whether this Code is inline code or not.
487       *
488       * @stability stable
489       */
490      readonly isInline: boolean;
491      private asset?;
492      /**
493       * @stability stable
494       */
495      constructor(directory: string, props: AssetImageCodeProps);
496      /**
497       * Called when the lambda or layer is initialized to allow this object to bind to the stack, add resources and have fun.
498       *
499       * @stability stable
500       */
501      bind(scope: Construct): CodeConfig;
502      /**
503       * Called after the CFN function resource has been created to allow the code class to bind to it.
504       *
505       * Specifically it's required to allow assets to add
506       * metadata for tooling like SAM CLI to be able to find their origins.
507       *
508       * @stability stable
509       */
510      bindToResource(resource: cdk.CfnResource, options?: ResourceBindOptions): void;
511  }
512  /**
513   * Options when creating an asset from a Docker build.
514   *
515   * @stability stable
516   */
517  export interface DockerBuildAssetOptions extends cdk.DockerBuildOptions {
518      /**
519       * The path in the Docker image where the asset is located after the build operation.
520       *
521       * @default /asset
522       * @stability stable
523       */
524      readonly imagePath?: string;
525      /**
526       * The path on the local filesystem where the asset will be copied using `docker cp`.
527       *
528       * @default - a unique temporary directory in the system temp directory
529       * @stability stable
530       */
531      readonly outputPath?: string;
532  }