英文:
Connect SPA to a docker backend in AWS
问题
如何部署一个运行在Docker中的Ktor后端容器以及访问该后端的SPA(使用Svelte)到AWS?我在网上做了一些研究,最佳方法似乎是使用弹性Beanstalk部署Docker容器,并将数据库连接到它。然后,使用CloudFront将前端部署到S3并提供服务。但我仍然无法找到如何连接这两者以在自己的域名上提供服务。在本地,我是通过使用Docker Compose启动我的后端和数据库,然后使用Nginx容器将/api
路由反向代理到后端容器,/
路由到前端。我发现这篇有用的文章使用Terraform来实现基本上我想做的事情(但使用了Flutter前端),但感觉有点过于复杂。
英文:
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.
答案1
得分: 0
你需要将Cloudfront放在静态资产(S3 存储桶)和后端 API(Elastic Beanstalk)之前。使用多个来源配置Cloudfront,将默认来源映射到S3存储桶,并将匹配“/api”路径的请求映射到后端。
或者,只需在Cloudfront中配置自定义域名,并在Elastic Beanstalk中配置自定义子域名。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论