News for hackers. Stuff that matters.

Ask HN: Serve static content from serverless AWS lambda function

We have an express+React typescript app that is executed from a serverless endpoint which is intended to ultimately move to AWS lambda.

The React bundle is served as static content along with its css, js etc files.

React app is hosted inside a single serverless project. The same is exposed from serverless.yml config as a function named static-router:

static-router: handler: src/server.handler events: - http: ANY / - http: ANY /{proxy+} So, on my local, it works absolutely fine! All the static content along with the index.html are getting served to the browser using serverless-offline

Static content served

However when I push the same to AWS using serverless deploy - all the static content is not getting served. Refer to this link: https://xjfxfyosml.execute-api.ap-south-1.amazonaws.com/dev/

How do I allow serving static content from the Lambda function which were working perfectly on my local?

What is missing here?

( 6 comments | 4 points | on HN )
Re:Ask HN: Serve static content from serverless AWS lambda f... by gtsteve on Monday October 21, 2019 @10:05AM (#21312372)
This question is probably best asked on StackOverflow.

I can't tell you why this problem is happening but you should consider uploading your static assets to S3, or you'll be paying for compute time when S3 can do it for cheaper or potentially free, and without burning your execution allowance.

Re:Ask HN: Serve static content from serverless AWS lambda f... by eahefnawy on Monday October 21, 2019 @07:33AM (#21311044)
Maybe Serverless Components could help? The backend component should be pretty easy for this use case:

https://github.com/serverless-components/backend

Re:Ask HN: Serve static content from serverless AWS lambda f... by xameeramir on Monday October 21, 2019 @09:57AM (#21312275)
@eahefnawy This is not for static pages. This is for web frameworks like express/hapi etc
Re:Ask HN: Serve static content from serverless AWS lambda f... by dyeje on Monday October 21, 2019 @10:05AM (#21312366)
Sorry, not familiar with this architecture. But isn't the common pattern here to just host the react app on a CDN? Then the serverless backend could just focus on fulfilling API requests instead of assets.
Re:Ask HN: Serve static content from serverless AWS lambda f... by ac360 on Monday October 21, 2019 @12:54PM (#21314471)
Re:Ask HN: Serve static content from serverless AWS lambda f... by solutionfocus on Monday October 21, 2019 @12:53PM (#21314454)
host your content on S3 as a website and front it with CloudFront. Use Lambda just for 'api' in your case.