-
Notifications
You must be signed in to change notification settings - Fork 4k
/
Copy pathimage-function.ts
71 lines (66 loc) · 2.09 KB
/
image-function.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
68
69
70
71
import * as ecr from '@aws-cdk/aws-ecr';
import { Construct } from 'constructs';
import { AssetImageCode, AssetImageCodeProps, EcrImageCode, EcrImageCodeProps, Code } from './code';
import { Function, FunctionOptions } from './function';
import { Handler } from './handler';
import { Runtime } from './runtime';
/**
* Properties to configure a new DockerImageFunction construct.
*/
export interface DockerImageFunctionProps extends FunctionOptions {
/**
* The source code of your Lambda function. You can point to a file in an
* Amazon Simple Storage Service (Amazon S3) bucket or specify your source
* code as inline text.
*/
readonly code: DockerImageCode;
}
/**
* Code property for the DockerImageFunction construct
*/
export abstract class DockerImageCode {
/**
* Use an existing ECR image as the Lambda code.
* @param repository the ECR repository that the image is in
* @param props properties to further configure the selected image
* @experimental
*/
public static fromEcr(repository: ecr.IRepository, props?: EcrImageCodeProps): DockerImageCode {
return {
_bind() {
return new EcrImageCode(repository, props);
},
};
}
/**
* Create an ECR image from the specified asset and bind it as the Lambda code.
* @param directory the directory from which the asset must be created
* @param props properties to further configure the selected image
* @experimental
*/
public static fromImageAsset(directory: string, props: AssetImageCodeProps = {}): DockerImageCode {
return {
_bind() {
return new AssetImageCode(directory, props);
},
};
}
/**
* Produce a `Code` instance from this `DockerImageCode`.
* @internal
*/
public abstract _bind(): Code;
}
/**
* Create a lambda function where the handler is a docker image
*/
export class DockerImageFunction extends Function {
constructor(scope: Construct, id: string, props: DockerImageFunctionProps) {
super(scope, id, {
...props,
handler: Handler.FROM_IMAGE,
runtime: Runtime.FROM_IMAGE,
code: props.code._bind(),
});
}
}