Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lambda-python): runtime is now required #18143

Merged
merged 3 commits into from
Dec 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/@aws-cdk/aws-lambda-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Define a `PythonFunction`:
```ts
new lambda.PythonFunction(this, 'MyFunction', {
entry: '/path/to/my/function', // required
runtime: Runtime.PYTHON_3_6, // required
index: 'my_index.py', // optional, defaults to 'index.py'
handler: 'my_exported_func', // optional, defaults to 'handler'
runtime: Runtime.PYTHON_3_6, // optional, defaults to lambda.Runtime.PYTHON_3_7
});
```

Expand Down Expand Up @@ -86,6 +86,7 @@ layer.
```ts
new lambda.PythonFunction(this, 'MyFunction', {
entry: '/path/to/my/function',
runtime: Runtime.PYTHON_3_6,
layers: [
new lambda.PythonLayerVersion(this, 'MyLayer', {
entry: '/path/to/my/layer', // point this to your library's directory
Expand Down
4 changes: 1 addition & 3 deletions packages/@aws-cdk/aws-lambda-python/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ export interface PythonFunctionProps extends lambda.FunctionOptions {
/**
* The runtime environment. Only runtimes of the Python family are
* supported.
*
* @default lambda.Runtime.PYTHON_3_7
*/
readonly runtime?: lambda.Runtime;
readonly runtime: lambda.Runtime;

/**
* Determines how asset hash is calculated. Assets will get rebuild and
Expand Down
8 changes: 8 additions & 0 deletions packages/@aws-cdk/aws-lambda-python/test/function.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ beforeEach(() => {
test('PythonFunction with defaults', () => {
new PythonFunction(stack, 'handler', {
entry: 'test/lambda-handler',
runtime: Runtime.PYTHON_3_8,
});

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

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

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

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

new PythonFunction(stack, 'source2', {
entry: 'test/lambda-handler-nodeps',
index: 'index.py',
handler: 'handler',
assetHashType: AssetHashType.SOURCE,
runtime: Runtime.PYTHON_3_8,
});

new PythonFunction(stack, 'output', {
entry: 'test/lambda-handler-nodeps',
index: 'index.py',
handler: 'handler',
assetHashType: AssetHashType.OUTPUT,
runtime: Runtime.PYTHON_3_8,
});

new PythonFunction(stack, 'custom', {
entry: 'test/lambda-handler-nodeps',
index: 'index.py',
handler: 'handler',
assetHash: 'MY_CUSTOM_HASH',
runtime: Runtime.PYTHON_3_8,
});

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