Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arditshala opened this issue Oct 2, 2020 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@arditshala
Copy link

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.

@MathiasHaudgaard
Copy link

+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

@arditshala
Copy link
Author

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

@mzahor
Copy link
Contributor

mzahor commented Dec 17, 2020

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 mzahor added bug Something isn't working duplicate This issue or pull request already exists labels Dec 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants