@aws-cdk/aws-lambda-python-alpha 2.3.0-alpha.0 → 2.4.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +184 -52
- package/.jsii.tabl.json +375 -79
- package/.warnings.jsii.js +18 -12
- package/LICENSE +1 -1
- package/NOTICE +1 -1
- package/README.md +103 -23
- package/lib/Dockerfile +7 -2
- package/lib/bundling.d.ts +15 -53
- package/lib/bundling.js +47 -60
- package/lib/function.d.ts +20 -50
- package/lib/function.js +14 -20
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/lib/layer.d.ts +12 -1
- package/lib/layer.js +4 -3
- package/lib/packaging.d.ts +40 -0
- package/lib/packaging.js +61 -0
- package/lib/types.d.ts +79 -0
- package/lib/types.js +3 -0
- package/package.json +6 -6
- package/rosetta/default.ts-fixture +1 -1
- package/lib/Dockerfile.dependencies +0 -22
package/.warnings.jsii.js
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
|
-
function _aws_cdk_aws_lambda_python_alpha_PythonFunction(p) {
|
|
2
|
-
}
|
|
3
1
|
function _aws_cdk_aws_lambda_python_alpha_PythonLayerVersion(p) {
|
|
4
2
|
}
|
|
5
|
-
function
|
|
6
|
-
if (p == null)
|
|
7
|
-
return;
|
|
8
|
-
visitedObjects.add(p);
|
|
9
|
-
if (!visitedObjects.has(p.compatibleArchitectures))
|
|
10
|
-
require("aws-cdk-lib/.warnings.jsii.js").aws_cdk_lib_aws_lambda_Architecture(p.compatibleArchitectures);
|
|
11
|
-
if (!visitedObjects.has(p.compatibleRuntimes))
|
|
12
|
-
require("aws-cdk-lib/.warnings.jsii.js").aws_cdk_lib_aws_lambda_Runtime(p.compatibleRuntimes);
|
|
13
|
-
visitedObjects.delete(p);
|
|
3
|
+
function _aws_cdk_aws_lambda_python_alpha_PythonFunction(p) {
|
|
14
4
|
}
|
|
15
5
|
function _aws_cdk_aws_lambda_python_alpha_PythonFunctionProps(p) {
|
|
16
6
|
if (p == null)
|
|
17
7
|
return;
|
|
18
8
|
visitedObjects.add(p);
|
|
9
|
+
if (!visitedObjects.has(p.bundling))
|
|
10
|
+
_aws_cdk_aws_lambda_python_alpha_BundlingOptions(p.bundling);
|
|
19
11
|
if (!visitedObjects.has(p.events))
|
|
20
12
|
require("aws-cdk-lib/.warnings.jsii.js").aws_cdk_lib_aws_lambda_IEventSource(p.events);
|
|
21
13
|
if (!visitedObjects.has(p.initialPolicy))
|
|
@@ -26,6 +18,20 @@ function _aws_cdk_aws_lambda_python_alpha_PythonFunctionProps(p) {
|
|
|
26
18
|
require("aws-cdk-lib/.warnings.jsii.js").aws_cdk_lib_aws_ec2_ISecurityGroup(p.securityGroups);
|
|
27
19
|
visitedObjects.delete(p);
|
|
28
20
|
}
|
|
21
|
+
function _aws_cdk_aws_lambda_python_alpha_PythonLayerVersionProps(p) {
|
|
22
|
+
if (p == null)
|
|
23
|
+
return;
|
|
24
|
+
visitedObjects.add(p);
|
|
25
|
+
if (!visitedObjects.has(p.bundling))
|
|
26
|
+
_aws_cdk_aws_lambda_python_alpha_BundlingOptions(p.bundling);
|
|
27
|
+
if (!visitedObjects.has(p.compatibleArchitectures))
|
|
28
|
+
require("aws-cdk-lib/.warnings.jsii.js").aws_cdk_lib_aws_lambda_Architecture(p.compatibleArchitectures);
|
|
29
|
+
if (!visitedObjects.has(p.compatibleRuntimes))
|
|
30
|
+
require("aws-cdk-lib/.warnings.jsii.js").aws_cdk_lib_aws_lambda_Runtime(p.compatibleRuntimes);
|
|
31
|
+
visitedObjects.delete(p);
|
|
32
|
+
}
|
|
33
|
+
function _aws_cdk_aws_lambda_python_alpha_BundlingOptions(p) {
|
|
34
|
+
}
|
|
29
35
|
function print(name, deprecationMessage) {
|
|
30
36
|
const deprecated = process.env.JSII_DEPRECATED;
|
|
31
37
|
const deprecationMode = ["warn", "fail", "quiet"].includes(deprecated) ? deprecated : "warn";
|
|
@@ -41,5 +47,5 @@ function print(name, deprecationMessage) {
|
|
|
41
47
|
const visitedObjects = new Set();
|
|
42
48
|
class DeprecationError extends Error {
|
|
43
49
|
}
|
|
44
|
-
module.exports = { print, _aws_cdk_aws_lambda_python_alpha_PythonFunction,
|
|
50
|
+
module.exports = { print, _aws_cdk_aws_lambda_python_alpha_PythonLayerVersion, _aws_cdk_aws_lambda_python_alpha_PythonFunction, _aws_cdk_aws_lambda_python_alpha_PythonFunctionProps, _aws_cdk_aws_lambda_python_alpha_PythonLayerVersionProps, _aws_cdk_aws_lambda_python_alpha_BundlingOptions };
|
|
45
51
|
module.exports.DeprecationError = DeprecationError;
|
package/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright 2018-
|
|
189
|
+
Copyright 2018-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/NOTICE
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
AWS Cloud Development Kit (AWS CDK)
|
|
2
|
-
Copyright 2018-
|
|
2
|
+
Copyright 2018-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
package/README.md
CHANGED
|
@@ -27,29 +27,61 @@ Define a `PythonFunction`:
|
|
|
27
27
|
```ts
|
|
28
28
|
new lambda.PythonFunction(this, 'MyFunction', {
|
|
29
29
|
entry: '/path/to/my/function', // required
|
|
30
|
+
runtime: Runtime.PYTHON_3_8, // required
|
|
30
31
|
index: 'my_index.py', // optional, defaults to 'index.py'
|
|
31
32
|
handler: 'my_exported_func', // optional, defaults to 'handler'
|
|
32
|
-
runtime: Runtime.PYTHON_3_6, // optional, defaults to lambda.Runtime.PYTHON_3_7
|
|
33
33
|
});
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
All other properties of `lambda.Function` are supported, see also the [AWS Lambda construct library](https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda).
|
|
37
37
|
|
|
38
|
-
##
|
|
38
|
+
## Python Layer
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
You may create a python-based lambda layer with `PythonLayerVersion`. If `PythonLayerVersion` detects a `requirements.txt`
|
|
41
|
+
or `Pipfile` or `poetry.lock` with the associated `pyproject.toml` at the entry path, then `PythonLayerVersion` will include the dependencies inline with your code in the
|
|
42
|
+
layer.
|
|
43
|
+
|
|
44
|
+
Define a `PythonLayerVersion`:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
new lambda.PythonLayerVersion(this, 'MyLayer', {
|
|
48
|
+
entry: '/path/to/my/layer', // point this to your library's directory
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
A layer can also be used as a part of a `PythonFunction`:
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
new lambda.PythonFunction(this, 'MyFunction', {
|
|
56
|
+
entry: '/path/to/my/function',
|
|
57
|
+
runtime: Runtime.PYTHON_3_8,
|
|
58
|
+
layers: [
|
|
59
|
+
new lambda.PythonLayerVersion(this, 'MyLayer', {
|
|
60
|
+
entry: '/path/to/my/layer', // point this to your library's directory
|
|
61
|
+
}),
|
|
62
|
+
],
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Packaging
|
|
67
|
+
|
|
68
|
+
If `requirements.txt`, `Pipfile` or `poetry.lock` exists at the entry path, the construct will handle installing all required modules in a [Lambda compatible Docker container](https://gallery.ecr.aws/sam/build-python3.7) according to the `runtime` and with the Docker platform based on the target architecture of the Lambda function.
|
|
43
69
|
|
|
44
70
|
Python bundles are only recreated and published when a file in a source directory has changed.
|
|
45
71
|
Therefore (and as a general best-practice), it is highly recommended to commit a lockfile with a
|
|
46
|
-
list of all transitive dependencies and their exact versions.
|
|
47
|
-
|
|
72
|
+
list of all transitive dependencies and their exact versions. This will ensure that when any dependency version is updated, the bundle asset is recreated and uploaded.
|
|
73
|
+
|
|
74
|
+
To that end, we recommend using [`pipenv`] or [`poetry`] which have lockfile support.
|
|
75
|
+
|
|
76
|
+
- [`pipenv`](https://pipenv-fork.readthedocs.io/en/latest/basics.html#example-pipfile-lock)
|
|
77
|
+
- [`poetry`](https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control)
|
|
48
78
|
|
|
49
|
-
|
|
79
|
+
Packaging is executed using the `Packaging` class, which:
|
|
50
80
|
|
|
51
|
-
|
|
52
|
-
|
|
81
|
+
1. Infers the packaging type based on the files present.
|
|
82
|
+
2. If it sees a `Pipfile` or a `poetry.lock` file, it exports it to a compatible `requirements.txt` file with credentials (if they're available in the source files or in the bundling container).
|
|
83
|
+
3. Installs dependencies using `pip`.
|
|
84
|
+
4. Copies the dependencies into an asset that is bundled for the Lambda package.
|
|
53
85
|
|
|
54
86
|
**Lambda with a requirements.txt**
|
|
55
87
|
|
|
@@ -73,23 +105,71 @@ To that end, we recommend using [`pipenv`] or [`poetry`] which has lockfile supp
|
|
|
73
105
|
```plaintext
|
|
74
106
|
.
|
|
75
107
|
├── lambda_function.py # exports a function named 'handler'
|
|
76
|
-
├── pyproject.toml #
|
|
77
|
-
├── poetry.lock # your poetry lock file
|
|
108
|
+
├── pyproject.toml # your poetry project definition
|
|
109
|
+
├── poetry.lock # your poetry lock file has to be present at the entry path
|
|
78
110
|
```
|
|
79
111
|
|
|
80
|
-
|
|
112
|
+
## Custom Bundling
|
|
81
113
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
114
|
+
Custom bundling can be performed by passing in additional build arguments that point to index URLs to private repos, or by using an entirely custom Docker images for bundling dependencies. The build args currently supported are:
|
|
115
|
+
|
|
116
|
+
- `PIP_INDEX_URL`
|
|
117
|
+
- `PIP_EXTRA_INDEX_URL`
|
|
118
|
+
- `HTTPS_PROXY`
|
|
119
|
+
|
|
120
|
+
Additional build args for bundling that refer to PyPI indexes can be specified as:
|
|
85
121
|
|
|
86
122
|
```ts
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
123
|
+
const entry = '/path/to/function';
|
|
124
|
+
const image = DockerImage.fromBuild(entry);
|
|
125
|
+
|
|
126
|
+
new lambda.PythonFunction(this, 'function', {
|
|
127
|
+
entry,
|
|
128
|
+
runtime: Runtime.PYTHON_3_8,
|
|
129
|
+
bundling: {
|
|
130
|
+
buildArgs: { PIP_INDEX_URL: "https://your.index.url/simple/", PIP_EXTRA_INDEX_URL: "https://your.extra-index.url/simple/" },
|
|
131
|
+
},
|
|
94
132
|
});
|
|
95
133
|
```
|
|
134
|
+
|
|
135
|
+
If using a custom Docker image for bundling, the dependencies are installed with `pip`, `pipenv` or `poetry` by using the `Packaging` class. A different bundling Docker image that is in the same directory as the function can be specified as:
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
const entry = '/path/to/function';
|
|
139
|
+
const image = DockerImage.fromBuild(entry);
|
|
140
|
+
|
|
141
|
+
new lambda.PythonFunction(this, 'function', {
|
|
142
|
+
entry,
|
|
143
|
+
runtime: Runtime.PYTHON_3_8,
|
|
144
|
+
bundling: { image },
|
|
145
|
+
});
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Custom Bundling with Code Artifact
|
|
149
|
+
|
|
150
|
+
To use a Code Artifact PyPI repo, the `PIP_INDEX_URL` for bundling the function can be customized (requires AWS CLI in the build environment):
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
import { execSync } from 'child_process';
|
|
154
|
+
|
|
155
|
+
const entry = '/path/to/function';
|
|
156
|
+
const image = DockerImage.fromBuild(entry);
|
|
157
|
+
|
|
158
|
+
const domain = 'my-domain';
|
|
159
|
+
const domainOwner = '111122223333';
|
|
160
|
+
const repoName = 'my_repo';
|
|
161
|
+
const region = 'us-east-1';
|
|
162
|
+
const codeArtifactAuthToken = execSync(`aws codeartifact get-authorization-token --domain ${domain} --domain-owner ${domainOwner} --query authorizationToken --output text`).toString().trim();
|
|
163
|
+
|
|
164
|
+
const indexUrl = `https://aws:${codeArtifactAuthToken}@${domain}-${domainOwner}.d.codeartifact.${region}.amazonaws.com/pypi/${repoName}/simple/`;
|
|
165
|
+
|
|
166
|
+
new lambda.PythonFunction(this, 'function', {
|
|
167
|
+
entry,
|
|
168
|
+
runtime: Runtime.PYTHON_3_8,
|
|
169
|
+
bundling: {
|
|
170
|
+
buildArgs: { PIP_INDEX_URL: indexUrl },
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
This type of an example should work for `pip` and `poetry` based dependencies, but will not work for `pipenv`.
|
package/lib/Dockerfile
CHANGED
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
ARG IMAGE=public.ecr.aws/sam/build-python3.7
|
|
4
4
|
FROM $IMAGE
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
ARG PIP_INDEX_URL
|
|
7
|
+
ARG PIP_EXTRA_INDEX_URL
|
|
8
|
+
ARG HTTPS_PROXY
|
|
9
|
+
|
|
10
|
+
# Upgrade pip (required by cryptography v3.4 and above, which is a dependency of poetry)
|
|
11
|
+
RUN pip install --upgrade pip
|
|
12
|
+
RUN pip install pipenv poetry
|
|
8
13
|
|
|
9
14
|
CMD [ "python" ]
|
package/lib/bundling.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { Architecture, AssetCode, Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
2
|
+
import { BundlingOptions as CdkBundlingOptions, DockerImage } from 'aws-cdk-lib';
|
|
3
|
+
import { BundlingOptions } from './types';
|
|
3
4
|
/**
|
|
4
5
|
* Dependency files to exclude from the asset hash.
|
|
5
6
|
*/
|
|
@@ -11,68 +12,29 @@ export declare const BUNDLER_DEPENDENCIES_CACHE = "/var/dependencies";
|
|
|
11
12
|
/**
|
|
12
13
|
* Options for bundling
|
|
13
14
|
*/
|
|
14
|
-
export interface BundlingOptions {
|
|
15
|
+
export interface BundlingProps extends BundlingOptions {
|
|
15
16
|
/**
|
|
16
17
|
* Entry path
|
|
17
18
|
*/
|
|
18
19
|
readonly entry: string;
|
|
19
20
|
/**
|
|
20
|
-
* The runtime
|
|
21
|
+
* The runtime environment.
|
|
21
22
|
*/
|
|
22
|
-
readonly runtime:
|
|
23
|
+
readonly runtime: Runtime;
|
|
23
24
|
/**
|
|
24
25
|
* The system architecture of the lambda function
|
|
25
|
-
*/
|
|
26
|
-
readonly architecture: lambda.Architecture;
|
|
27
|
-
/**
|
|
28
|
-
* Output path suffix ('python' for a layer, '.' otherwise)
|
|
29
|
-
*/
|
|
30
|
-
readonly outputPathSuffix: string;
|
|
31
|
-
/**
|
|
32
|
-
* Determines how asset hash is calculated. Assets will get rebuild and
|
|
33
|
-
* uploaded only if their hash has changed.
|
|
34
26
|
*
|
|
35
|
-
*
|
|
36
|
-
* directory will cause the asset to rebuild. This means, for example, that in
|
|
37
|
-
* order to pick up a new dependency version, a change must be made to the
|
|
38
|
-
* source tree. Ideally, this can be implemented by including a dependency
|
|
39
|
-
* lockfile in your source tree or using fixed dependencies.
|
|
40
|
-
*
|
|
41
|
-
* If the asset hash is set to `OUTPUT`, the hash is calculated after
|
|
42
|
-
* bundling. This means that any change in the output will cause the asset to
|
|
43
|
-
* be invalidated and uploaded. Bear in mind that `pip` adds timestamps to
|
|
44
|
-
* dependencies it installs, which implies that in this mode Python bundles
|
|
45
|
-
* will _always_ get rebuild and uploaded. Normally this is an anti-pattern
|
|
46
|
-
* since build
|
|
47
|
-
*
|
|
48
|
-
* @default AssetHashType.SOURCE By default, hash is calculated based on the
|
|
49
|
-
* contents of the source directory. If `assetHash` is also specified, the
|
|
50
|
-
* default is `CUSTOM`. This means that only updates to the source will cause
|
|
51
|
-
* the asset to rebuild.
|
|
27
|
+
* @default Architecture.X86_64
|
|
52
28
|
*/
|
|
53
|
-
readonly
|
|
54
|
-
/**
|
|
55
|
-
* Specify a custom hash for this asset. If `assetHashType` is set it must
|
|
56
|
-
* be set to `AssetHashType.CUSTOM`. For consistency, this custom hash will
|
|
57
|
-
* be SHA256 hashed and encoded as hex. The resulting hash will be the asset
|
|
58
|
-
* hash.
|
|
59
|
-
*
|
|
60
|
-
* NOTE: the hash is used in order to identify a specific revision of the asset, and
|
|
61
|
-
* used for optimizing and caching deployment activities related to this asset such as
|
|
62
|
-
* packaging, uploading to Amazon S3, etc. If you chose to customize the hash, you will
|
|
63
|
-
* need to make sure it is updated every time the asset changes, or otherwise it is
|
|
64
|
-
* possible that some deployments will not be invalidated.
|
|
65
|
-
*
|
|
66
|
-
* @default - based on `assetHashType`
|
|
67
|
-
*/
|
|
68
|
-
readonly assetHash?: string;
|
|
29
|
+
readonly architecture?: Architecture;
|
|
69
30
|
}
|
|
70
31
|
/**
|
|
71
32
|
* Produce bundled Lambda asset code
|
|
72
33
|
*/
|
|
73
|
-
export declare
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
34
|
+
export declare class Bundling implements CdkBundlingOptions {
|
|
35
|
+
static bundle(options: BundlingProps): AssetCode;
|
|
36
|
+
readonly image: DockerImage;
|
|
37
|
+
readonly command: string[];
|
|
38
|
+
constructor(props: BundlingProps);
|
|
39
|
+
private createBundlingCommand;
|
|
40
|
+
}
|
package/lib/bundling.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const fs = require("fs");
|
|
3
|
+
exports.Bundling = exports.BUNDLER_DEPENDENCIES_CACHE = exports.DEPENDENCY_EXCLUDES = void 0;
|
|
5
4
|
const path = require("path");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
5
|
+
const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
|
|
6
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
7
|
+
const packaging_1 = require("./packaging");
|
|
8
8
|
/**
|
|
9
9
|
* Dependency files to exclude from the asset hash.
|
|
10
10
|
*/
|
|
@@ -16,65 +16,52 @@ exports.BUNDLER_DEPENDENCIES_CACHE = '/var/dependencies';
|
|
|
16
16
|
/**
|
|
17
17
|
* Produce bundled Lambda asset code
|
|
18
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
|
-
* Checks to see if the `entry` directory contains a type of dependency that
|
|
56
|
-
* we know how to install.
|
|
57
|
-
*/
|
|
58
|
-
function stageDependencies(entry, stagedir) {
|
|
59
|
-
const prefixes = [
|
|
60
|
-
'Pipfile',
|
|
61
|
-
'pyproject',
|
|
62
|
-
'poetry',
|
|
63
|
-
'requirements.txt',
|
|
64
|
-
];
|
|
65
|
-
let found = false;
|
|
66
|
-
for (const file of fs.readdirSync(entry)) {
|
|
67
|
-
for (const prefix of prefixes) {
|
|
68
|
-
if (file.startsWith(prefix)) {
|
|
69
|
-
fs.copyFileSync(path.join(entry, file), path.join(stagedir, file));
|
|
70
|
-
found = true;
|
|
71
|
-
}
|
|
19
|
+
class Bundling {
|
|
20
|
+
constructor(props) {
|
|
21
|
+
var _a;
|
|
22
|
+
const { entry, runtime, architecture = aws_lambda_1.Architecture.X86_64, outputPathSuffix = '', image, } = props;
|
|
23
|
+
const outputPath = path.join(aws_cdk_lib_1.AssetStaging.BUNDLING_OUTPUT_DIR, outputPathSuffix);
|
|
24
|
+
const bundlingCommands = this.createBundlingCommand({
|
|
25
|
+
entry,
|
|
26
|
+
inputDir: aws_cdk_lib_1.AssetStaging.BUNDLING_INPUT_DIR,
|
|
27
|
+
outputDir: outputPath,
|
|
28
|
+
});
|
|
29
|
+
const defaultImage = aws_cdk_lib_1.DockerImage.fromBuild(path.join(__dirname, '../lib'), {
|
|
30
|
+
buildArgs: {
|
|
31
|
+
...(_a = props.buildArgs) !== null && _a !== void 0 ? _a : {},
|
|
32
|
+
IMAGE: runtime.bundlingImage.image,
|
|
33
|
+
},
|
|
34
|
+
platform: architecture.dockerPlatform,
|
|
35
|
+
});
|
|
36
|
+
this.image = image !== null && image !== void 0 ? image : defaultImage;
|
|
37
|
+
this.command = ['bash', '-c', chain(bundlingCommands)];
|
|
38
|
+
}
|
|
39
|
+
static bundle(options) {
|
|
40
|
+
return aws_lambda_1.Code.fromAsset(options.entry, {
|
|
41
|
+
assetHash: options.assetHash,
|
|
42
|
+
assetHashType: options.assetHashType,
|
|
43
|
+
exclude: exports.DEPENDENCY_EXCLUDES,
|
|
44
|
+
bundling: new Bundling(options),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
createBundlingCommand(options) {
|
|
48
|
+
var _a;
|
|
49
|
+
const packaging = packaging_1.Packaging.fromEntry(options.entry);
|
|
50
|
+
let bundlingCommands = [];
|
|
51
|
+
bundlingCommands.push((_a = packaging.exportCommand) !== null && _a !== void 0 ? _a : '');
|
|
52
|
+
if (packaging.dependenciesFile) {
|
|
53
|
+
bundlingCommands.push(`python -m pip install -r ${packaging_1.DependenciesFile.PIP} -t ${options.outputDir}`);
|
|
72
54
|
}
|
|
55
|
+
;
|
|
56
|
+
bundlingCommands.push(`cp -R ${options.inputDir} ${options.outputDir}`);
|
|
57
|
+
return bundlingCommands;
|
|
73
58
|
}
|
|
74
|
-
return found;
|
|
75
59
|
}
|
|
76
|
-
exports.
|
|
60
|
+
exports.Bundling = Bundling;
|
|
61
|
+
/**
|
|
62
|
+
* Chain commands
|
|
63
|
+
*/
|
|
77
64
|
function chain(commands) {
|
|
78
65
|
return commands.filter(c => !!c).join(' && ');
|
|
79
66
|
}
|
|
80
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
67
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYnVuZGxpbmcuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJidW5kbGluZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFBQSw2QkFBNkI7QUFDN0IsdURBQWdGO0FBQ2hGLDZDQUErRjtBQUMvRiwyQ0FBMEQ7QUFHMUQ7O0dBRUc7QUFDVSxRQUFBLG1CQUFtQixHQUFHLENBQUMsT0FBTyxDQUFDLENBQUM7QUFFN0M7O0dBRUc7QUFDVSxRQUFBLDBCQUEwQixHQUFHLG1CQUFtQixDQUFDO0FBd0I5RDs7R0FFRztBQUNILE1BQWEsUUFBUTtJQWFuQixZQUFZLEtBQW9COztRQUM5QixNQUFNLEVBQ0osS0FBSyxFQUNMLE9BQU8sRUFDUCxZQUFZLEdBQUcseUJBQVksQ0FBQyxNQUFNLEVBQ2xDLGdCQUFnQixHQUFHLEVBQUUsRUFDckIsS0FBSyxHQUNOLEdBQUcsS0FBSyxDQUFDO1FBRVYsTUFBTSxVQUFVLEdBQUcsSUFBSSxDQUFDLElBQUksQ0FBQywwQkFBWSxDQUFDLG1CQUFtQixFQUFFLGdCQUFnQixDQUFDLENBQUM7UUFFakYsTUFBTSxnQkFBZ0IsR0FBRyxJQUFJLENBQUMscUJBQXFCLENBQUM7WUFDbEQsS0FBSztZQUNMLFFBQVEsRUFBRSwwQkFBWSxDQUFDLGtCQUFrQjtZQUN6QyxTQUFTLEVBQUUsVU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W1hbmRPcHRpb25zIHtcbiAgcmVhZG9ubHkgZW50cnk6IHN0cmluZztcbiAgcmVhZG9ubHkgaW5wdXREaXI6IHN0cmluZztcbiAgcmVhZG9ubHkgb3V0cHV0RGlyOiBzdHJpbmc7XG59XG5cbi8qKlxuICogQ2hhaW4gY29tbWFuZHNcbiAqL1xuZnVuY3Rpb24gY2hhaW4oY29tbWFuZHM6IHN0cmluZ1tdKTogc3RyaW5nIHtcbiAgcmV0dXJuIGNvbW1hbmRzLmZpbHRlcihjID0+ICEhYykuam9pbignICYmICcpO1xufVxuIl19
|
package/lib/function.d.ts
CHANGED
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import * as lambda from 'aws-cdk-lib/aws-lambda';
|
|
2
|
-
import { AssetHashType } from 'aws-cdk-lib';
|
|
3
1
|
import { Construct } from 'constructs';
|
|
2
|
+
import { Function, FunctionOptions, Runtime } from 'aws-cdk-lib/aws-lambda';
|
|
3
|
+
import { BundlingOptions } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* (experimental) Properties for a PythonFunction.
|
|
6
6
|
*
|
|
7
7
|
* @experimental
|
|
8
8
|
*/
|
|
9
|
-
export interface PythonFunctionProps extends
|
|
9
|
+
export interface PythonFunctionProps extends FunctionOptions {
|
|
10
10
|
/**
|
|
11
|
-
* (experimental)
|
|
11
|
+
* (experimental) Path to the source of the function or the location for dependencies.
|
|
12
12
|
*
|
|
13
13
|
* @experimental
|
|
14
14
|
*/
|
|
15
15
|
readonly entry: string;
|
|
16
|
+
/**
|
|
17
|
+
* (experimental) The runtime environment.
|
|
18
|
+
*
|
|
19
|
+
* Only runtimes of the Python family are
|
|
20
|
+
* supported.
|
|
21
|
+
*
|
|
22
|
+
* @default Runtime.PYTHON_3_7
|
|
23
|
+
* @experimental
|
|
24
|
+
*/
|
|
25
|
+
readonly runtime: Runtime;
|
|
16
26
|
/**
|
|
17
27
|
* (experimental) The path (relative to entry) to the index file containing the exported handler.
|
|
18
28
|
*
|
|
@@ -28,62 +38,22 @@ export interface PythonFunctionProps extends lambda.FunctionOptions {
|
|
|
28
38
|
*/
|
|
29
39
|
readonly handler?: string;
|
|
30
40
|
/**
|
|
31
|
-
* (experimental)
|
|
32
|
-
*
|
|
33
|
-
* Only runtimes of the Python family are
|
|
34
|
-
* supported.
|
|
35
|
-
*
|
|
36
|
-
* @default lambda.Runtime.PYTHON_3_7
|
|
37
|
-
* @experimental
|
|
38
|
-
*/
|
|
39
|
-
readonly runtime?: lambda.Runtime;
|
|
40
|
-
/**
|
|
41
|
-
* (experimental) Determines how asset hash is calculated. Assets will get rebuild and uploaded only if their hash has changed.
|
|
42
|
-
*
|
|
43
|
-
* If asset hash is set to `SOURCE` (default), then only changes to the source
|
|
44
|
-
* directory will cause the asset to rebuild. This means, for example, that in
|
|
45
|
-
* order to pick up a new dependency version, a change must be made to the
|
|
46
|
-
* source tree. Ideally, this can be implemented by including a dependency
|
|
47
|
-
* lockfile in your source tree or using fixed dependencies.
|
|
48
|
-
*
|
|
49
|
-
* If the asset hash is set to `OUTPUT`, the hash is calculated after
|
|
50
|
-
* bundling. This means that any change in the output will cause the asset to
|
|
51
|
-
* be invalidated and uploaded. Bear in mind that `pip` adds timestamps to
|
|
52
|
-
* dependencies it installs, which implies that in this mode Python bundles
|
|
53
|
-
* will _always_ get rebuild and uploaded. Normally this is an anti-pattern
|
|
54
|
-
* since build
|
|
55
|
-
*
|
|
56
|
-
* @default AssetHashType.SOURCE By default, hash is calculated based on the
|
|
57
|
-
* contents of the source directory. This means that only updates to the
|
|
58
|
-
* source will cause the asset to rebuild.
|
|
59
|
-
* @experimental
|
|
60
|
-
*/
|
|
61
|
-
readonly assetHashType?: AssetHashType;
|
|
62
|
-
/**
|
|
63
|
-
* (experimental) Specify a custom hash for this asset.
|
|
64
|
-
*
|
|
65
|
-
* If `assetHashType` is set it must
|
|
66
|
-
* be set to `AssetHashType.CUSTOM`. For consistency, this custom hash will
|
|
67
|
-
* be SHA256 hashed and encoded as hex. The resulting hash will be the asset
|
|
68
|
-
* hash.
|
|
41
|
+
* (experimental) Bundling options to use for this function.
|
|
69
42
|
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* packaging, uploading to Amazon S3, etc. If you chose to customize the hash, you will
|
|
73
|
-
* need to make sure it is updated every time the asset changes, or otherwise it is
|
|
74
|
-
* possible that some deployments will not be invalidated.
|
|
43
|
+
* Use this to specify custom bundling options like
|
|
44
|
+
* the bundling Docker image, asset hash type, custom hash, architecture, etc.
|
|
75
45
|
*
|
|
76
|
-
* @default -
|
|
46
|
+
* @default - Use the default bundling Docker image, with x86_64 architecture.
|
|
77
47
|
* @experimental
|
|
78
48
|
*/
|
|
79
|
-
readonly
|
|
49
|
+
readonly bundling?: BundlingOptions;
|
|
80
50
|
}
|
|
81
51
|
/**
|
|
82
52
|
* (experimental) A Python Lambda function.
|
|
83
53
|
*
|
|
84
54
|
* @experimental
|
|
85
55
|
*/
|
|
86
|
-
export declare class PythonFunction extends
|
|
56
|
+
export declare class PythonFunction extends Function {
|
|
87
57
|
/**
|
|
88
58
|
* @experimental
|
|
89
59
|
*/
|