Skip to content
This repository was archived by the owner on Apr 5, 2025. It is now read-only.

Commit e0ebfa5

Browse files
committed
feat: add architecture option to generate layers for ARM64
1 parent 3a1cf63 commit e0ebfa5

File tree

6 files changed

+48
-12
lines changed

6 files changed

+48
-12
lines changed

.projen/deps.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const project = new awscdk.AwsCdkConstructLibrary({
44
authorUrl: 'https://aws.amazon.com',
55
authorOrganization: true,
66
keywords: ['aws', 'cdk', 'powertools', 'python', 'layer', 'lambda', 'devax', 'typescript', 'nodejs'],
7-
cdkVersion: '2.24.1',
7+
cdkVersion: '2.44.0',
88
defaultReleaseBranch: 'main',
99
majorVersion: 2,
1010
name: 'cdk-aws-lambda-powertools-layer',

package.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lambda-powertools-layer.ts

+21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as path from 'path';
22
import { aws_lambda as lambda } from 'aws-cdk-lib';
3+
import { Architecture } from 'aws-cdk-lib/aws-lambda';
34
import { Construct } from 'constructs';
45

56
/**
@@ -26,6 +27,11 @@ export interface PowertoolsLayerProps {
2627
* the runtime of the layer
2728
*/
2829
readonly runtimeFamily?: lambda.RuntimeFamily;
30+
31+
/**
32+
* The compatible architectures for the layer
33+
*/
34+
readonly compatibleArchitectures?: lambda.Architecture[];
2935
}
3036

3137
/**
@@ -70,6 +76,8 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
7076
const runtimeFamily = props?.runtimeFamily ?? lambda.RuntimeFamily.PYTHON;
7177
const languageName = getLanguageNameFromRuntimeFamily(runtimeFamily);
7278
const dockerFilePath = path.join(__dirname, `../layer/${languageName}`);
79+
const compatibleArchitectures = props?.compatibleArchitectures ?? [lambda.Architecture.X86_64];
80+
7381
console.log(`path ${dockerFilePath}`);
7482
super(scope, id, {
7583
code: lambda.Code.fromDockerBuild(dockerFilePath, {
@@ -80,10 +88,12 @@ export class LambdaPowertoolsLayer extends lambda.LayerVersion {
8088
props?.version,
8189
),
8290
},
91+
platform: getPlatformNameFromArchitectures(compatibleArchitectures),
8392
}),
8493
layerVersionName: props?.layerVersionName ? props?.layerVersionName : undefined,
8594
license: 'MIT-0',
8695
compatibleRuntimes: getRuntimesFromRuntimeFamily(runtimeFamily),
96+
compatibleArchitectures,
8797
description: `Lambda Powertools for ${languageName}${
8898
props?.includeExtras ? ' with Extras' : ''
8999
} ${props?.version ? `version ${props?.version}` : 'latest version'}`.trim(),
@@ -120,3 +130,14 @@ function getLanguageNameFromRuntimeFamily(runtimeFamily: lambda.RuntimeFamily):
120130
return 'Unknown';
121131
}
122132
}
133+
134+
function getPlatformNameFromArchitectures(architectures: lambda.Architecture[]): string {
135+
if (architectures.length == 1) {
136+
return architectures[0].dockerPlatform;
137+
} else {
138+
// if we have multiple architectures, we default to x86_64, hoping for the
139+
// layer not to have any architecture specific code or at least contain
140+
// binary code for all architectures
141+
return Architecture.X86_64.dockerPlatform;
142+
}
143+
}

test/lambda-powertools-python-layer.test.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Stack } from 'aws-cdk-lib';
22
import { Template } from 'aws-cdk-lib/assertions';
3-
import { RuntimeFamily } from 'aws-cdk-lib/aws-lambda';
3+
import { Architecture, RuntimeFamily } from 'aws-cdk-lib/aws-lambda';
44
import { LambdaPowertoolsLayer } from '../src';
55

66

@@ -31,6 +31,21 @@ describe('with no configuration the construct', () => {
3131
});
3232
});
3333

34+
describe('with arm64 architecture', () => {
35+
const stack = new Stack();
36+
new LambdaPowertoolsLayer(stack, 'PowertoolsLayer', {
37+
runtimeFamily: RuntimeFamily.PYTHON,
38+
compatibleArchitectures: [Architecture.ARM_64],
39+
});
40+
const template = Template.fromStack(stack);
41+
test('synthesizes successfully', () => {
42+
template.hasResourceProperties('AWS::Lambda::LayerVersion', {
43+
Description: 'Lambda Powertools for Python latest version',
44+
CompatibleArchitectures: ['arm64'],
45+
});
46+
});
47+
});
48+
3449
describe('for layerVersionName configuraiton the construct', () => {
3550
test('synthisizes to a layer with provided name', () => {
3651
const stack = new Stack();

yarn.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)