Skip to content

Commit

Permalink
fix(lambda-python-alpha): use function architecture (#18696) (#28449)
Browse files Browse the repository at this point in the history
With this change, architecture when bundling is inferred from the target architecture of the Lambda function.

Closes #18696.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
lucacucchetti committed Dec 21, 2023
1 parent 16a1a62 commit c724d27
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-lambda-python-alpha/lib/function.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class PythonFunction extends Function {
entry,
runtime,
skip: !Stack.of(scope).bundlingRequired,
// define architecture based on the target architecture of the function, possibly overriden in bundling options
architecture: props.architecture,
...props.bundling,
}),
handler: resolvedHandler,
Expand Down
16 changes: 15 additions & 1 deletion packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import { Template } from 'aws-cdk-lib/assertions';
import { Code, Runtime } from 'aws-cdk-lib/aws-lambda';
import { Code, Runtime, Architecture } from 'aws-cdk-lib/aws-lambda';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import { AssetHashType, DockerImage, Stack } from 'aws-cdk-lib';
import { PythonFunction } from '../lib';
Expand Down Expand Up @@ -217,3 +217,17 @@ test('Do not skip bundling when stack requires it', () => {

spy.mockRestore();
});

test('PythonFunction specifying architecture', () => {
new PythonFunction(stack, 'handler', {
entry: path.join(__dirname, 'lambda-handler'),
runtime: Runtime.PYTHON_3_11,
architecture: Architecture.ARM_64,
});

expect(Bundling.bundle).toHaveBeenCalledWith(
expect.objectContaining({
architecture: Architecture.ARM_64,
}),
);
});

0 comments on commit c724d27

Please sign in to comment.