sns-sqs-big-payload icon indicating copy to clipboard operation
sns-sqs-big-payload copied to clipboard

Lambda makes the event/records lowercase keys therefore a JSON.parse() error is thrown

Open arditshala opened this issue 4 years ago • 3 comments

Hi, AWS Lambda makes all the keys in the object lowercase, and your Consumer class for example is trying to do something like message.Body however this is undefined, because the key Body is actually body, therefore an error Invalid JSON at position 0 character 'u' is thrown.

I think you cannot change it to 'body' directly since the implementation works otherwise in environment outside Lambda, what I would suggest is to pass a key like integration: 'lambda' when an instance of the class is created and then you know if your class is being used in the context of lambda i.e lowercase record (event) keys.

arditshala avatar Oct 02 '20 02:10 arditshala

+1

@arditshala how did you manage to get the error message from the EventEmitter into cloudwatch? I only managed to get the error message by adding a console.log in the catch clause in the sqs-consumer file at line 128

MathiasHaudgaard avatar Oct 15 '20 08:10 MathiasHaudgaard

@MathiasHaudgaard Well, I did the same thing 😄 . That should also change I guess, the methods should throw the errors so then we can catch.

arditshala avatar Nov 02 '20 11:11 arditshala

Hi, I think this is related #20 . I'm thinking about 2 things:

  1. adding an option as suggested above (integartion: 'lambda')
  2. providing a transformMessage callback which receives an actual message, and not just the Body part. It will allow us to do any transformations.

First approach is easier to use for lambda, second one is tad harder to use but can be useful in other situations.

@blumamir WDYT?

mzahor avatar Dec 17 '20 10:12 mzahor