So, the Serverless framework is pretty awesome!
But … out of the box, it needs a few options setup to work as well as a regular server!
- Serving binary files (images/pdf files/etc – stuff your app generates and tries to send to the user)
By default API Gateway will have all sorts of encoding issues if you don’t set this up, and try to send binary files to your users. To set it up;
provider: apiGateway: binaryMediaTypes: - '*/*'
This is one which I hadn’t even thought of until I was browsing the site on a slowish connection!
By default content will be sent from API Gateway uncompressed. Whilst your users might not see much of a different, you could find yourself sending a lot more data than is needed (I had over a 10x saving in bandwidth … from 100kb to 6kb for JSON data).
To enable it, set;
provider: name: aws apiGateway: minimumCompressionSize: 1024
1024 (1kb) is used as a minimum size at which compression is used. You can set it to ‘0’ to compress everything, but the docs mention if you do-so, some small responses (less than 1kb) might actually be larger.
Ref for these, and more options; https://serverless.com/framework/docs/providers/aws/events/apigateway/