Reputation: 3011
Current AWS configuration which is serving 3 webapps -
Here ELB is taking care of SSL offloading. Currently the Node JS application is deployed on a EC2 machine. It is taking care of handling the backend APIs as well as serving the static files for the 3 SPA react webapps.
We are looking to improve on this by separating out the frontend and backend. We are thinking of moving the 3 SPA react webapps into a single S3 bucket. Each will sit in its own directory on this S3 bucket. The S3 bucket will be configured for static website hosting. We will still have the node JS instance for service backend APIs.
We are looking to avoid using cloud front to route traffic from ELB to S3 since these are internal webapps with limited number of users from a particular region.
Also the lambda function has to route the traffic based on rules -
/ui/site3/* --> route traffic to S3 bucket site3 directory
Upvotes: 0
Views: 1285
Reputation: 4516
Yes, you can implement a Lambda that retrieves content from S3. You simply need to extract the request path from the invocation event, translate that to whatever S3 location you're using, retrieve the file, and package it in the response.
BUT
You're limited to 1MB response data, so if you have any images or other large files, you won't be able to serve them (doc).
And you'll be paying Lambda invocation costs for every file that you retrieve, which is admittedly small.
And you'll be increasing the time to retrieve each file, which will slow down your web-app. How much depends on how many static assets you're loading.
A better solution, if you want to split static and dynamic content and don't want to use CloudFront, would be to spin up another Node.JS server on a different port, and have the ALB point at it.
Upvotes: 3
Reputation: 35238
Application load balancers already support path based routing. But won't support the S3 bucket as a valid target, so you'd want a Lambda for that to echo the contents.
So
Upvotes: 0