CoorpAcademy / serverless-plugins

Collection of serverless plugins :zap:
230 stars 131 forks source link

serverless-offline-sqs: Incompatible with latest serverless-offline. Can't have certain variables outside handler #143

Open zoellner opened 4 years ago

zoellner commented 4 years ago

I'm running into issues using the latest versions of serverless-offline and serverless-offline-sqs

This might be related to the general discussion in https://github.com/CoorpAcademy/serverless-plugins/issues/102

I created a very minimal demo here: https://github.com/zoellner/offline-sqs-bug

The issue comes down to a very simple piece of code:

const AWS = require('aws-sdk');

exports.handler = async function handleEvent(event) {
  console.log(event);
  return true;
}

Triggering two messages to this code will throw an error (the first one runs fine). The problem is in the variable require that's outside the event handler. The demo with the aws-sdk is just an example since that's a very common dependency. I've seen a similar issue using pino logger and others.

benhutchins commented 4 years ago

Might want to check https://github.com/dherault/serverless-offline/issues/1075 to see if that is the issue you're having.

zoellner commented 4 years ago

Yes, I think it comes down to the same underlying change in serverless-offline (was a bit too far into the weeds to realize when I opened this ticket and forgot to link it)

But the proposed workarounds for serverless-offline api endpoints (useChildProcesses and allowCache) don't work in the combination with serverless-offline-sqs. I'm assuming that there's something in the way the plugin calls the lambdas that ignores some of these settings.

sambP commented 3 years ago

for a quick fix, this combination worked for me: "serverless-offline": "5.12.1", "serverless-offline-sqs": "3.1.3",