diff --git a/packages/@aws-cdk/aws-lambda/lib/function.ts b/packages/@aws-cdk/aws-lambda/lib/function.ts index fffd20decd8d9..c749e7950d42d 100644 --- a/packages/@aws-cdk/aws-lambda/lib/function.ts +++ b/packages/@aws-cdk/aws-lambda/lib/function.ts @@ -573,8 +573,13 @@ export class Function extends FunctionBase { */ public readonly deadLetterQueue?: sqs.IQueue; + /** + * The architecture of this Lambda Function (this is an optional attribute and defaults to X86_64). + */ + public readonly architecture?: Architecture; public readonly permissionsNode = this.node; + protected readonly canCreatePermissions = true; private readonly layers: ILayerVersion[] = []; @@ -721,6 +726,8 @@ export class Function extends FunctionBase { this.runtime = props.runtime; + this.architecture = props.architecture; + if (props.layers) { if (props.runtime === Runtime.FROM_IMAGE) { throw new Error('Layers are not supported for container image functions'); diff --git a/packages/@aws-cdk/aws-lambda/test/function.test.ts b/packages/@aws-cdk/aws-lambda/test/function.test.ts index 66d18e663e7f9..7a8ff6d1bed80 100644 --- a/packages/@aws-cdk/aws-lambda/test/function.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/function.test.ts @@ -2226,7 +2226,16 @@ describe('function', () => { architectures: [lambda.Architecture.X86_64, lambda.Architecture.ARM_64], })).toThrow(/one architecture must be specified/); }); - + test('Architecture is properly readable from the function', () => { + const stack = new cdk.Stack(); + const fn = new lambda.Function(stack, 'MyFunction', { + code: lambda.Code.fromInline('foo'), + runtime: lambda.Runtime.NODEJS_14_X, + handler: 'index.handler', + architecture: lambda.Architecture.ARM_64, + }); + expect(fn.architecture?.name).toEqual('arm64'); + }); }); function newTestLambda(scope: constructs.Construct) {