From 42844bdb2ca9b22d11e99f29925273dc6c4b4fb7 Mon Sep 17 00:00:00 2001 From: ljacobsson Date: Tue, 25 Jul 2023 15:23:10 +0200 Subject: [PATCH] relay should run at 128mb --- src/commands/local/lib/connect.js | 2 +- src/commands/local/lib/relay/relay.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/commands/local/lib/connect.js b/src/commands/local/lib/connect.js index a82c6da..26853bb 100644 --- a/src/commands/local/lib/connect.js +++ b/src/commands/local/lib/connect.js @@ -338,7 +338,7 @@ async function updateFunctions(func, lambdaClient) { const updateFunctionConfigurationCommand = new UpdateFunctionConfigurationCommand({ FunctionName: functionName, Timeout: parseInt(process.env.SAMP_TIMEOUT || 60), - MemorySize: 256, + MemorySize: 128, Handler: 'relay.handler', }); await lambdaClient.send(updateFunctionConfigurationCommand); diff --git a/src/commands/local/lib/relay/relay.js b/src/commands/local/lib/relay/relay.js index 33be185..8fb9b64 100644 --- a/src/commands/local/lib/relay/relay.js +++ b/src/commands/local/lib/relay/relay.js @@ -77,8 +77,21 @@ export const handler = async (event, context) => { }; function publishEvent(event, context) { - const sessionId = new Date().getTime() + '-' + Math.floor((Math.random() * 1000000) + 1); // Unique ID for this debug session + const sessionId = new Date().getTime() + '-' + Math.floor((Math.random() * 1000000) + 1); // Unique ID for this rounndtrip + const totalPayload = JSON.stringify({ event, context, envVars: process.env, sessionId }); + if (totalPayload.length > 64) { + const chunks = totalPayload.match(/.{1,64}/g); + chunks.forEach((chunk, index) => { + const payload = JSON.stringify({ event: 'chunk', chunk, index, totalChunks: chunks.length }); + publish(payload, sessionId); + }); + } else { + publish(totalPayload, sessionId); + } +} + +function publish(payload, sessionId) { client.subscribe(`lambda-debug/callback/${config.mac}/${sessionId}`); - client.publish('lambda-debug/event/' + config.mac, JSON.stringify({ event, context, envVars: process.env, sessionId })); + client.publish('lambda-debug/event/' + config.mac, payload); }