From c724d277277c45b421dcd89ee1a6d4b54f942d3b Mon Sep 17 00:00:00 2001 From: Luca Cucchetti <43192486+lucacucchetti@users.noreply.github.com> Date: Thu, 21 Dec 2023 21:57:53 +0000 Subject: [PATCH] fix(lambda-python-alpha): use function architecture (#18696) (#28449) 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 ++ .../test/function.test.ts | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) 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..a101ed521e0b6 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 @@ -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'; @@ -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