From 3c082cc45423f983a640545fa5d4ab3e6f2fbae4 Mon Sep 17 00:00:00 2001 From: Martin Sonnberger Date: Fri, 18 Sep 2026 10:35:10 +0200 Subject: [PATCH] test(aws-serverless): Avoid SAM runtime port collisions Co-Authored-By: GPT-6 --- .../aws-serverless-layer/src/stack.ts | 11 ++++++----- .../test-applications/aws-serverless/src/stack.ts | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/aws-serverless-layer/src/stack.ts b/dev-packages/e2e-tests/test-applications/aws-serverless-layer/src/stack.ts index ed77302ec088..df5a076ef56d 100644 --- a/dev-packages/e2e-tests/test-applications/aws-serverless-layer/src/stack.ts +++ b/dev-packages/e2e-tests/test-applications/aws-serverless-layer/src/stack.ts @@ -10,7 +10,8 @@ import { globSync } from 'glob'; const LAMBDA_FUNCTIONS_DIR = './src/lambda-functions-layer'; const LAMBDA_FUNCTION_TIMEOUT = 10; const LAYER_DIR = './node_modules/@sentry/aws-serverless/'; -export const SAM_PORT = Number(process.env.SAM_PORT) || 7120; +// SAM allocates runtime container ports in [5000, 9000) before binding its own endpoint. +export const SAM_PORT = Number(process.env.SAM_PORT) || 17120; /** Match SAM / Docker to this machine so Apple Silicon does not mix arm64 images with an x86_64 template default. */ function samLambdaArchitecture(): 'arm64' | 'x86_64' { @@ -102,13 +103,13 @@ export class LocalLambdaStack extends Stack { try { const response = await fetch(`http://127.0.0.1:${port}/`); - if (response.ok || response.status === 404) { + if (response.status === 404 && response.headers.get('x-amzn-errortype') === 'PathNotFoundLocally') { console.log(`[LocalLambdaStack] SAM stack is ready`); return; } - } catch { - await new Promise(resolve => setTimeout(resolve, 1000)); - } + } catch {} + + await new Promise(resolve => setTimeout(resolve, 1000)); } throw new Error(`[LocalLambdaStack] Failed to start SAM stack after ${timeout}ms`); diff --git a/dev-packages/e2e-tests/test-applications/aws-serverless/src/stack.ts b/dev-packages/e2e-tests/test-applications/aws-serverless/src/stack.ts index a2a201bd9486..f314643572c2 100644 --- a/dev-packages/e2e-tests/test-applications/aws-serverless/src/stack.ts +++ b/dev-packages/e2e-tests/test-applications/aws-serverless/src/stack.ts @@ -9,7 +9,8 @@ import { execFileSync } from 'node:child_process'; const LAMBDA_FUNCTIONS_DIR = './src/lambda-functions-npm'; const LAMBDA_FUNCTION_TIMEOUT = 10; -export const SAM_PORT = Number(process.env.SAM_PORT) || 7120; +// SAM allocates runtime container ports in [5000, 9000) before binding its own endpoint. +export const SAM_PORT = Number(process.env.SAM_PORT) || 17120; /** Match SAM / Docker to this machine so Apple Silicon does not mix arm64 images with an x86_64 template default. */ function samLambdaArchitecture(): 'arm64' | 'x86_64' { @@ -143,13 +144,13 @@ export class LocalLambdaStack extends Stack { try { const response = await fetch(`http://127.0.0.1:${port}/`); - if (response.ok || response.status === 404) { + if (response.status === 404 && response.headers.get('x-amzn-errortype') === 'PathNotFoundLocally') { console.log(`[LocalLambdaStack] SAM stack is ready`); return; } - } catch { - await new Promise(resolve => setTimeout(resolve, 1000)); - } + } catch {} + + await new Promise(resolve => setTimeout(resolve, 1000)); } throw new Error(`[LocalLambdaStack] Failed to start SAM stack after ${timeout}ms`);