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

How to parse event.body #1

Open
chopchop505 opened this issue Mar 2, 2018 · 3 comments
Open

How to parse event.body #1

chopchop505 opened this issue Mar 2, 2018 · 3 comments

Comments

@chopchop505
Copy link

Thanks for the code example.
I'm trying to setup a gateway that accepts protobuf encoded responses.
It seems like AWS converts the binary payload to a JSON string in event.body?

When I try to decode this, I'm getting errors.
Could you show an example of decoding event.body (https://github.com/theburningmonk/lambda-protobuf-demo/blob/master/functions/proto.js#L10)

@theburningmonk
Copy link
Owner

Are you deploying using the Serverless framework?

@chopchop505
Copy link
Author

chopchop505 commented Mar 2, 2018 via email

@theburningmonk
Copy link
Owner

ok, then here are the things you're going to need:

  • in the serverless.yml use the serverless-apigw-binary to add application/x-protobuf as a media type that should be treated as binary
  • in the request to API Gateway endpoint, set Content-Type as application/x-protobuf

then API Gateway would treat the request body as binary and base64 encode it, you should be able to see this as the event.isBase64Encoded should also be true.

If these doesn't work, then maybe point me to a gist of your code so I can see what's going on. Unfortunately the whole setup is still a bit "magic" :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants