Search code examples
amazon-web-servicesdockeramazon-elastic-beanstalkamazon-cloudfront

Connect SPA to a docker backend in AWS


How would I deploy a docker container backend (ktor running in docker) and a SPA that accesses the backend (svelte) to aws? I've done research online and the best I could come up with was to use elastic beanstalk to deploy my docker container and to connect my database to it. Then, use cloudfront to deploy my frontend to s3 and serve that. However, I'm still unable to find how I would connect the two to serve both on my own domain. The way I'm doing it locally is by using docker compose to launch my backend and my database. Then, I use an nginx container to reverse proxy the /api route to the backend container and / to my frontend. I found this useful article that uses Terraform to do basically what I want to do (but with a flutter frontend) but it feels a bit overkill.


Solution

  • You need to place Cloudfront in front of both your static assets (S3 bucket) and your backend API (Elastic Beanstalk). Configure Cloudfront with multiple origins, mapping the default origin to your S3 bucket, and requests that match the /api path to the backend.

    Alternatively, just configure your custom domain in Cloudfront, and a custom subdomain in Elastic Beanstalk.