From 001ecfeb2e92c5021aa50c7ac98bc3de554674e3 Mon Sep 17 00:00:00 2001 From: Bruno Garcia Date: Wed, 29 Nov 2023 12:29:51 -0300 Subject: [PATCH] Correctly lookup AWS region. --- runtimes/web/webrtc-signal-server/src/main.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/runtimes/web/webrtc-signal-server/src/main.ts b/runtimes/web/webrtc-signal-server/src/main.ts index df4bb662..c79f1546 100644 --- a/runtimes/web/webrtc-signal-server/src/main.ts +++ b/runtimes/web/webrtc-signal-server/src/main.ts @@ -3,13 +3,12 @@ import { ApiGatewayManagementApiClient, PostToConnectionCommand } from "@aws-sdk export const handler: APIGatewayProxyWebsocketHandlerV2 = async ({ body, requestContext }) => { async function sendToPeer (source: string, target: string, message: object) { + const region = process.env.AWS_REGION ?? process.env.AWS_DEFAULT_REGION ?? "us-east-1"; const client = new ApiGatewayManagementApiClient({ apiVersion: "2018-11-29", endpoint: process.env.IS_OFFLINE ? "http://localhost:3001" - : requestContext.domainName.endsWith(".wasm4.org") - ? `https://${requestContext.apiId}.execute-api.us-east-1.amazonaws.com/${requestContext.stage}` - : `https://${requestContext.domainName}/${requestContext.stage}`, + : `https://${requestContext.apiId}.execute-api.${region}.amazonaws.com/${requestContext.stage}`, credentials: process.env.IS_OFFLINE ? { accessKeyId: "offline", secretAccessKey: "offline" } : undefined,