From 80f8838f426860d69581048d9f68022f8d9eccd6 Mon Sep 17 00:00:00 2001 From: Luca Cucchetti Date: Thu, 21 Dec 2023 11:14:07 +0000 Subject: [PATCH] fix(lambda-python-alpha): use function architecture (#18696) 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* --- .../aws-lambda-python-alpha/lib/function.ts | 2 ++ .../aws-lambda-python-alpha/test/function.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/packages/@aws-cdk/aws-lambda-python-alpha/lib/function.ts b/packages/@aws-cdk/aws-lambda-python-alpha/lib/function.ts index 4dd3a23e06dc7..510725c028af2 100644 --- a/packages/@aws-cdk/aws-lambda-python-alpha/lib/function.ts +++ b/packages/@aws-cdk/aws-lambda-python-alpha/lib/function.ts @@ -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, diff --git a/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts b/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts index a8bf7ffaceafb..6874c02444186 100644 --- a/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda-python-alpha/test/function.test.ts @@ -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, + }), + ); +}); \ No newline at end of file