Hey everyone, I’ve built a backend project using K...
# getting-started
v
Hey everyone, I’ve built a backend project using Ktor with a PostgreSQL database, and I’m looking to deploy it. I’m not very experienced with deployment yet, and since I’m not sure whether this project will generate any revenue, I’d prefer a low-cost or free option to start with. I heard AWS Lambda has a free tier, but I’m not sure how to deploy a Ktor server there or if it’s even the right approach. Also, I’m a bit confused about the difference between running Ktor normally and running it in Docker—are they the same or do they serve different purposes? Would appreciate any guidance!
r
These questions aren't really specific to Kotlin and may be better suited for other help forums, but I'll offer what I can. First of all, regardless of how you deploy/host the ktor server, you'll also need to find a way to host your database. Plenty of options like AWS RDS, Supabase, Neon, etc. Regarding Docker, it sounds like you need to read up more on what Docker is and why it's useful, but my summary is: it's a standardized way of packaging applications, regardless of whether they're built with JVM, python, Node.js, whatever. If a cloud provider can run docker containers, then users are able to run anything they want as long as they package it in docker first. Now for you, since AWS Lambda does provide Java runtimes, you probably don't need docker unless your app requires other special things installed outside the JRE. Speaking of AWS Lambda, I don't think the way it receives requests is actually compatible with running an HTTP server like ktor. From what I see in their docs, the request is delivered to a specific function in your code. So you'd end up stripping out the ktor layer and keep just the internal logic. If you do go that route, here's their tutorial. The key is that you compile to a jar, upload the jar, and say what function inside the jar is set up to receive the requests. I think GCP's Cloud Run Services would be able to run an HTTP server as-is though. GCP's postres offering is under the umbrella they call Cloud SQL Here's a separate AWS tutorial for your overall scenario, but it may not be free.
s
I've only done very little work on AWS so what I say is likely not complete, but like Ryan already mentioned one doesn't deploy a server to AWS Lambda, that's simply not what Lambda is for additionally it's not the only AWS service you'd need. For one AWS Lambda isn't even reachable from the internet to start from. So (my knowledge here is 6 years old and might be no longer relevant) But first you need to configure ApiGateway to forward request e.g. to Lambda. But Lamda is more for glue code that ties other AWS services (e.g. S3: Database, SES: Simple Email Service, ...) together so adapting your Ktor service is likely not as trivial as stripping away Ktor (it might, it depends). But if you got a server you want to deploy, than maybe what you really want is rent an EC2 instance and deploy your service on it. (As far es I know you'd still need ApiGateway to forward internet requests to your EC2 instance). But since you seem to be unsure what AWS to use, maybe you don't need AWS at all? (sorry for opening up the possibility space). But the alternatice to using EC2 instance on AWS would be to rent a managed server at Hetzner and deploy your Ktor service there!?
I might be completely off! I just found a YouTube video callled: "Deploying Quarkus based Amazon Lambdas" so maybe there are also Ktor based Amazon Lambdas ??
v
@rkechols Thanks for the explanation — that makes sense. Since Lambda isn’t a good fit for a full Ktor server and Docker seems like the better option, where would you recommend deploying a Dockerized Ktor app so it’s simple, cheap, and scalable?
@Stephan Schröder Thanks for the detailed explanation, that helps a lot! Since Lambda isn’t suitable for running a full Ktor server, what would you recommend as the simplest, cheapest, and scalable place to deploy a Dockerized Ktor app?
s
I don't know the deployment landscape (I'm way more Dev than DevOps). I know that generally Hetzner is a popular choice for reanting a server (at least if you live in the EU). But that advice isn't even specific to your use-case.
r
@Stephan Schröder Lambda does now have the option to expose a public URL. But that still doesn't fix the general issue. Here are some other potential choices to research: • GCP Cloud Run Services • Vercel • Heroku You'll need to check which of those support JVM or at least docker, and if the pricing model fits your needs