I'm in the process of developing a web application that involves training or fine-tuning a custom machine learning model—think text-to-image generation. For the frontend, I'm looking at modern frameworks like React or Next.js, and I'm considering using FastAPI for the backend. However, I'm open to suggestions if there's a better framework for machine learning inference and API serving. I'm seeking advice from those who have experience deploying ML-powered apps on AWS. Specifically, I have questions about the best AWS services for: training or fine-tuning the model (should I go with SageMaker, or EC2 with GPU?), serving the model in production (what's the best approach for the inference API?), hosting the backend (is FastAPI the way to go?), deploying the frontend (Amplify vs EC2 vs S3 + CloudFront), and any common pitfalls when integrating ML models with a React or Next.js frontend. Any guidance would be greatly appreciated, especially from those who have taken a similar architecture to production!
3 Answers
You could convert your app to Next.js without too much hassle! If you're looking for examples or tools, check out my GitHub repo where I've shared some insights: https://github.com/bebeal/vite-aws.
For training or fine-tuning your model, I'd recommend SageMaker if you prefer a managed infrastructure. However, if you want more control, going for EC2 with GPU might be the way to go.
When it comes to serving the model, using SageMaker Endpoints can simplify the process. If you're sticking with FastAPI, you could containerize your app and deploy it on ECS Fargate or App Runner for easy scaling and management.
For the frontend, I’d suggest using S3 with CloudFront if you're dealing with static files, but if you plan on server-side rendering with Next.js, AWS Amplify could be a better option. Just remember to route all your machine learning calls through your backend; don’t interact with the model from the browser directly.
It sounds like you've got a solid foundation! For the backend, you definitely don't 'host' FastAPI by itself; you’ll want a compute service that runs it. Using SageMaker for model deployment is great, and yes, it can provide you an endpoint along with an API key so you can call it from your React app.
If you're looking for alternatives, an API is generally the best route to connect your model to the frontend. Keeping the model and backend on the same instance is one way to manage things, but you could also separate them—like using SageMaker for the model and something like Lambda or Fargate for your backend. Plus, having a backend (FastAPI or Lambda) definitely helps manage requests between the frontend and your model efficiently.
Related Questions
Cloudflare Origin SSL Certificate Setup Guide
How To Effectively Monetize A Site With Ads