Skip to content

Commit d31aac2

Browse files
committed
ci: use docker host's architecture for functions
1 parent 8c2295e commit d31aac2

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

test/function.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
1+
import { exec } from 'node:child_process';
12
import * as fs from 'node:fs/promises';
23
import * as path from 'node:path';
4+
import { promisify } from 'node:util';
35
import { App, Stack } from 'aws-cdk-lib';
46
import { Match, Template } from 'aws-cdk-lib/assertions';
5-
import { Runtime } from 'aws-cdk-lib/aws-lambda';
7+
import { Architecture, Runtime } from 'aws-cdk-lib/aws-lambda';
68
import { PythonFunction } from '../src';
9+
const execAsync = promisify(exec);
710

811
const resourcesPath = path.resolve(__dirname, 'resources');
912

13+
/**
14+
* Determine the optimal Lambda Function architecture based on the Docker host's CPU
15+
* architecture. This allows GHA runners to work without slow QEMU Arm emulation.
16+
*
17+
* @returns The Lambda Architecture
18+
*/
19+
async function getDockerHostArch(): Promise<Architecture> {
20+
try {
21+
const { stdout } = await execAsync('docker info --format "{{.Architecture}}"');
22+
const arch = stdout.trim();
23+
return arch === 'aarch64' ? Architecture.ARM_64 : Architecture.X86_64;
24+
} catch (error) {
25+
console.error('Error getting Docker host architecture:', error);
26+
throw error;
27+
}
28+
}
1029

1130
test('Create a function from basic_app', async () => {
1231
const app = new App({});
@@ -16,6 +35,7 @@ test('Create a function from basic_app', async () => {
1635
index: 'handler.py',
1736
handler: 'lambda_handler',
1837
runtime: Runtime.PYTHON_3_12,
38+
architecture: await getDockerHostArch(),
1939
});
2040

2141
const template = Template.fromStack(stack);
@@ -44,6 +64,7 @@ test('Create a function with workspaces_app', async () => {
4464
index: 'app_handler.py',
4565
handler: 'handle_event',
4666
runtime: Runtime.PYTHON_3_10,
67+
architecture: await getDockerHostArch(),
4768
});
4869

4970
const template = Template.fromStack(stack);

0 commit comments

Comments
 (0)