1+ import { exec } from 'node:child_process' ;
12import * as fs from 'node:fs/promises' ;
23import * as path from 'node:path' ;
4+ import { promisify } from 'node:util' ;
35import { App , Stack } from 'aws-cdk-lib' ;
46import { 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' ;
68import { PythonFunction } from '../src' ;
9+ const execAsync = promisify ( exec ) ;
710
811const 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
1130test ( '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