Hosting a Plumber API on AWS
I’ve been putting together a small proof-of-concept API using R and plumber. It works flawlessly on my local machine and I was planning on deploying it on an EC2 instance to demo it for a client. However, I ran into a snag: despite opening the required port in my Security Group I was not able to access the API. This is what I needed to do to get it working.
This Didn’t Work
I spun up an EC2 instance and applied a very liberal Security Group: access allowed on all ports from any location. Disaster from a security perspective, but flexible enough to just to get things working.
I installed R and all of the required dependencies and the started the API.
Everything looking good so far.
I tested the API locally on the EC2 instance using
curl and it worked as expected. Awesome! I felt like I was on the finishing straight.
Next I tried to access it using the browser from my local machine.
Not good. I checked to see if I could access it using
Same story. Time to do some research.
A combination of Google and StackOverflow (as usual) came to the rescue.
First I checked for any firewall rules that might be blocking the port.
Nothing untoward there. Next I checked what ports were being listened on.
Aha! So something is listening on port 8000 but only on the loopback interface. That’s probably the problem.
I had to rummage through the
plumber source on GitHub to find this, but it turns out that you can specify a
host parameter as well.
Let’s check those ports again.
The API should now be visible outside of
This small change made all the difference. The API now works perfectly from the EC2 instance.
Note to self (again!): what works locally might very well not work when deployed.