Skip to content

Commit 1041af1

Browse files
author
cod1k
committed
Update Lambda fixture with platform-specific host-ip handling
Replaces `docker network prune` with `docker network rm` for better control and adds a condition to handle `host.docker.internal` for non-darwin/windows platforms, ensuring compatibility with various environments.
1 parent 632f0b9 commit 1041af1

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

dev-packages/e2e-tests/test-applications/aws-serverless/tests/lambda-fixtures.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { LocalLambdaStack, SAM_PORT, getHostIp } from '../src/stack';
55
import { writeFileSync } from 'node:fs';
66
import { spawn, execSync } from 'node:child_process';
77
import { LambdaClient } from '@aws-sdk/client-lambda';
8+
import { platform } from 'node:process';
89

910
const DOCKER_NETWORK_NAME = 'lambda-test-network';
1011
const SAM_TEMPLATE_FILE = 'sam.template.yml';
@@ -16,7 +17,7 @@ export const test = base.extend<{ testEnvironment: LocalLambdaStack; lambdaClien
1617
async ({}, use) => {
1718
console.log('[testEnvironment fixture] Setting up AWS Lambda test infrastructure');
1819

19-
execSync('docker network prune -f');
20+
execSync(`docker network rm -f ${DOCKER_NETWORK_NAME}`);
2021
execSync(`docker network create --driver bridge ${DOCKER_NETWORK_NAME}`);
2122

2223
const hostIp = await getHostIp();
@@ -44,6 +45,10 @@ export const test = base.extend<{ testEnvironment: LocalLambdaStack; lambdaClien
4445
'--skip-pull-image',
4546
];
4647

48+
if ('host.docker.internal' === hostIp && !['darwin', 'windows'].includes(platform)) {
49+
args.push('--add-host', `${hostIp}:host-gateway`);
50+
}
51+
4752
if (process.env.NODE_VERSION) {
4853
args.push('--invoke-image', `public.ecr.aws/lambda/nodejs:${process.env.NODE_VERSION}`);
4954
}

0 commit comments

Comments
 (0)