Question: Currently I have a setup where an API Gateway accepts a `.wav` file from a POST request and sends the `base64` encoded data from the audio file to a lambda function that I have as the handler using their Binary Support system.

I need to convert that base64 encoding of the audio file from the gateway back into a `.wav` format *without* writing to a new file and reading because AWS lambdas are a read-only file system.

I've tried doing `new Buffer(data, 'base64').toString('binary')` hoping that would work but it didn't and there isn't a whole lot of information about how to do this.

Answer: 
There are mainly two [limitations](http://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html) you need to look into when using API Gateway and Lambda for your use case.

* Maximum size of the audio file is 10MB
* If you need to store the file for processing in /tmp you can hold upto 512MB

Therefore mostly you will be constrained with 10MB limit for the audio file.

For this kind of processing, one alternative option is to use the following flow.

1. Using API Gateway and Lambda, request for a [AWS CloudFront Signed URL](http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-signed-urls.html) to upload the audio file to AWS S3.
2. Then upload the file directly from the client to S3.
3. Having a Lambda trigger from S3 bucket to a Lambda function for processing (Max file size is 512 MB)
Figure out the issue for anyone curious.

When API Gateway encodes the body of the request with their Binary Support system, they also encode the `WebKitBoundary` heading and tail data from the body if it exists.

It just cut out the front and tail of the encoding pertaining to that data so all that remained was strictly `.wav` data then recreated it as a `Buffer` using...

```
let audio = new Buffer(body, 'base64').toString('binary')

// Sequence of replacements and slices to remove WebKitBoundary header and tail

const audioBuffer = new Buffer(audio, 'binary')

```

The result of `audioBuffer` is the exact equivalent of simply reading a `.wav` file using the `fs` module.