Skip to content

Commit 98f1bb1

Browse files
fix(lambda-python): runtime is now required (#18143)
BREAKING CHANGE: Runtime is now required for `LambdaPython` fixes #10248 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent aa7c160 commit 98f1bb1

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

packages/@aws-cdk/aws-lambda-python/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Define a `PythonFunction`:
2727
```ts
2828
new lambda.PythonFunction(this, 'MyFunction', {
2929
entry: '/path/to/my/function', // required
30+
runtime: Runtime.PYTHON_3_6, // required
3031
index: 'my_index.py', // optional, defaults to 'index.py'
3132
handler: 'my_exported_func', // optional, defaults to 'handler'
32-
runtime: Runtime.PYTHON_3_6, // optional, defaults to lambda.Runtime.PYTHON_3_7
3333
});
3434
```
3535

@@ -86,6 +86,7 @@ layer.
8686
```ts
8787
new lambda.PythonFunction(this, 'MyFunction', {
8888
entry: '/path/to/my/function',
89+
runtime: Runtime.PYTHON_3_6,
8990
layers: [
9091
new lambda.PythonLayerVersion(this, 'MyLayer', {
9192
entry: '/path/to/my/layer', // point this to your library's directory

packages/@aws-cdk/aws-lambda-python/lib/function.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,8 @@ export interface PythonFunctionProps extends lambda.FunctionOptions {
3434
/**
3535
* The runtime environment. Only runtimes of the Python family are
3636
* supported.
37-
*
38-
* @default lambda.Runtime.PYTHON_3_7
3937
*/
40-
readonly runtime?: lambda.Runtime;
38+
readonly runtime: lambda.Runtime;
4139

4240
/**
4341
* Determines how asset hash is calculated. Assets will get rebuild and

packages/@aws-cdk/aws-lambda-python/test/function.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ beforeEach(() => {
4545
test('PythonFunction with defaults', () => {
4646
new PythonFunction(stack, 'handler', {
4747
entry: 'test/lambda-handler',
48+
runtime: Runtime.PYTHON_3_8,
4849
});
4950

5051
expect(bundle).toHaveBeenCalledWith(expect.objectContaining({
@@ -62,6 +63,7 @@ test('PythonFunction with index in a subdirectory', () => {
6263
entry: 'test/lambda-handler-sub',
6364
index: 'inner/custom_index.py',
6465
handler: 'custom_handler',
66+
runtime: Runtime.PYTHON_3_8,
6567
});
6668

6769
expect(bundle).toHaveBeenCalledWith(expect.objectContaining({
@@ -78,12 +80,14 @@ test('throws when index is not py', () => {
7880
expect(() => new PythonFunction(stack, 'Fn', {
7981
entry: 'test/lambda-handler',
8082
index: 'index.js',
83+
runtime: Runtime.PYTHON_3_8,
8184
})).toThrow(/Only Python \(\.py\) index files are supported/);
8285
});
8386

8487
test('throws when entry does not exist', () => {
8588
expect(() => new PythonFunction(stack, 'Fn', {
8689
entry: 'notfound',
90+
runtime: Runtime.PYTHON_3_8,
8791
})).toThrow(/Cannot find index file at/);
8892
});
8993

@@ -99,27 +103,31 @@ test('allows specifying hash type', () => {
99103
entry: 'test/lambda-handler-nodeps',
100104
index: 'index.py',
101105
handler: 'handler',
106+
runtime: Runtime.PYTHON_3_8,
102107
});
103108

104109
new PythonFunction(stack, 'source2', {
105110
entry: 'test/lambda-handler-nodeps',
106111
index: 'index.py',
107112
handler: 'handler',
108113
assetHashType: AssetHashType.SOURCE,
114+
runtime: Runtime.PYTHON_3_8,
109115
});
110116

111117
new PythonFunction(stack, 'output', {
112118
entry: 'test/lambda-handler-nodeps',
113119
index: 'index.py',
114120
handler: 'handler',
115121
assetHashType: AssetHashType.OUTPUT,
122+
runtime: Runtime.PYTHON_3_8,
116123
});
117124

118125
new PythonFunction(stack, 'custom', {
119126
entry: 'test/lambda-handler-nodeps',
120127
index: 'index.py',
121128
handler: 'handler',
122129
assetHash: 'MY_CUSTOM_HASH',
130+
runtime: Runtime.PYTHON_3_8,
123131
});
124132

125133
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', {

0 commit comments

Comments
 (0)