I'm using API Gateway Lambda proxy integration and trying to return a binary application/protobuf response. No matter what I do, the response body is always a base64 encoded string
- I have
application/protobufsetup as abinary media typesin APIG - My client (javascript) is sending following headers in the
POST:Accept: application/protobuf Content-Type: application/protobuf - My lambda is responing with
content-type: application/protobuf, and correctly setting theIsBase64EncodedLambda response totrue
How do you get APIG to base64 decode the string? I swear I had this working a few months ago when I 1st tried this.
Note: I've also tried */* as a binary media types
Some related posts to add background:
- https://github.com/twitchtv/twirp/issues/81
- https://github.com/awslabs/aws-serverless-express/issues/39#issuecomment-276019222
Update:
Turns out I can only get it working if binary media type is set to */*. The client Accept header has no impact once it is set to this.
Many bad side effects of using */* because every response is attempted to get decoded (even when IsBase64Encoded is false or not set)
I thought it wasn't decoding because Chrome network inspect tools will always show binary data as base64 encoded in the Preview tab. You can see the protobuf in the Response tab.
*/*on responses that were not binary. I was just making an educated guess that if APIG was configured to this, it would try to base64 decode EVERY response. Now that you mention this, I'm wondering if APIG only does the decode ifIsBase64Encodedis true. However that doesn't make sense in my head. If this were the case why the need for APIGbinary media typein the 1st place. - rynopisBase64EncodedandbinaryMediaTypes. I'll probably keep tinkering and update that repo with more details as I confirm them... - Scott Willeke