ramazon-web-servicesamazon-ec2deploymentplumber

How to Keep a Plumber API Running on AWS EC2 or Explore Alternative Deployment Options?


I am new to AWS and currently working on deploying a Plumber API written in R. This API serves predictions using a pre-trained GAMLSS model. I have set up an EC2 instance with Amazon Linux 2 where R and all the required libraries are installed. The R script for the API and the model file (RDS format) are both uploaded to the EC2 instance. I can run the API using the Rscript command, and it works perfectly when accessed via the public IP of the EC2 instance. For example, using a curl command or browser request, I can successfully get predictions from the API. I am thinking to run it in the background using methods like nohup or tmux, I feel this approach may not be robust enough for a production-ready solution. The API and model are stable, and there are no plans to change them in the future.

I want the API to keep running continuously, and to serve predictions for a public website. Given that the R script and model are static and unlikely to change, what is the best way to deploy this API on AWS? Should I continue running it in the background on EC2, or should I explore alternative solutions like Lambda, ECS, or EKS? I’m looking for a cost-effective and scalable solution that adheres to AWS best practices. Any guidance or suggestions would be greatly appreciated.


Solution

  • Lambda is not suitable in your case for many reasons:

    Your current setup is great, but surely depending on how big the production load is, you can add Autoscaling group to make it scalable if the traffic increases, and add a load balancer on top of it, then your API calls endpoint will be always the same, and you can put the EC2s in private subnet for better security.

    or you can use ECS and containerize the Plumber API and run it on AWS Fargate (serverless) or EC2, but for that you need to create the Docker image for your API, this will be better in term of Scalability, Reliability, and Cost-effective when using Fargate for small workloads, and you will not have to manage the most of things.

    Always consider simplicity first—avoid using complex services when a simpler setup can effectively meet your requirements. A small, well-optimized setup is often sufficient and easier to manage.