sns-sqs-big-payload
sns-sqs-big-payload copied to clipboard
Lambda makes the event/records lowercase keys therefore a JSON.parse() error is thrown
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.
+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 Well, I did the same thing 😄 . That should also change I guess, the methods should throw
the errors so then we can catch.
Hi, I think this is related #20 . I'm thinking about 2 things:
- adding an option as suggested above (
integartion: 'lambda'
) - providing a
transformMessage
callback which receives an actual message, and not just theBody
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?