Skip to content
AWS lambda CORS proxy
Java Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
LICENSE
README
package-lock.json
package.json
pom.xml
run-serverless.sh
serverless.yml
template.yaml

README

This is a failed experiment to attempt generalized CORS proxying of arbitrary URLs via AWS lambda. You can use this for CORS proxying a simple API as-is, but longer responses (such as binary blobs) will fail due to memory/response size limitations of lambda. The API is the same as cors-anywhere.

The main reasons:
- To return binary data from a lambda, you need to pipe it through Base64 encoding, which is cumbersome and slow

- Because lambda requires a JSON response, there's no method to stream the body, which is problematic for large responses since the entire response needs to be buffered into memory before being returned. The implementation found here does try to minimize memory usage by streaming the body out inline, but it seems that the caller ends up buffering it into a JSON blob and hence the high watermark on memory use for the lambda is proportional to the response size.

- Lambda has a hard response size limit of a few megs, and the API Gateway imposes a timeout of 30s. Both of these are prohibitive to a general web proxy.

For a nicer solution to this problem, there's a Cloudflare worker we've developed: https://github.com/mozilla/hubs-ops/blob/master/workers/cors-proxy.js
You can’t perform that action at this time.