Live data from Hacker News

Deploying front-end websites to S3 with CloudFront

ilhicas.com

11–20 of 33 posts

Re: Deploying front-end websites to S3 with CloudFront

#11
post #6

Configuring CORS is probably the biggest pain about this approach and is necessary if you want to send data to and from an API. This guide should probably mention it or link another guide.

I've found a fairly workable solution is to have an origin for the API in CloudFront and a behaviour to route /api/* to that origin. Saves any CORS headaches. Obviously this won't work in all cases.

Wasn't aware of this, will definitely try it next time around. Thanks!

Re: Deploying front-end websites to S3 with CloudFront

#12
post #9

Earlier quoted context omitted.

Just change the Access-Control-Allow-Origin header. Am I missing something?

Access-Control-Allow-Credentials too and it needs to be configured on both the client and the server.

If the API is not yours, why not set up a proxy on your domain (where you can change the origin header)? Envoy, nginx, etc.

Re: Deploying front-end websites to S3 with CloudFront

#14
post #13

A problem my team hits with micro projects with this is: virtual routes like `/login` doesn’t map to a file. What can be done about that?

/login makes me think your website isn't really static.

Regardless, you can use extensionless links with your static website if you rename the file from login.html to login, then change the file metadata to Content-Type: 'text/html'

Re: Deploying front-end websites to S3 with CloudFront

#15
post #3

If it's just a personal website, you might find it easier to use GitHub Pages (or GitLab's equivalent) and Cloudflare. Both are free for any reasonable personal website usage. If you don't want to run a build of your static site generator on your computer and upload the result to GitHub every time you make a change, you can just use Jekyll and GitHub will build it for you. I think GitLab supports other static site ge…

CF is not necessary anymore for SSL since GH can issue LetsEncrypt certificates automatically. https://help.github.com/en/github/working-with-github-pages/...

True. I find that the other features (analytics, better DNS interface, caching) make it worthwhile for me. Also, the original article mentioned CloudFront.

Re: Deploying front-end websites to S3 with CloudFront

#16
post #13

A problem my team hits with micro projects with this is: virtual routes like `/login` doesn’t map to a file. What can be done about that?

Like a SPA? You use a something like react router and set the S3 error page to your index. I've deployed many SPAs to AWS S3/ Cloudfront. You have to handle the 404 page in app

Here's a SO post https://stackoverflow.com/questions/51218979/react-router-do...

Re: Deploying front-end websites to S3 with CloudFront

#18
You should have a look at AWS Amplify Console https://aws.amazon.com/amplify/console/ It’s specifically designed to do most of this for you. I’ve been using it for static site work recently and it’s awesome. It also does plenty more and can be used for full stack dev but it’s great if you just need static site hosting and build pipelines. No need to have the build locally and uses gitops for build and auto generates environments based off branch name patterns.

Re: Deploying front-end websites to S3 with CloudFront

#19
post #13

A problem my team hits with micro projects with this is: virtual routes like `/login` doesn’t map to a file. What can be done about that?

You can also use Lambda@Edge with CloudFront to do any kind of logic required, like redirects, rewrites, etc...
Post reply on HN