Free and Easy Ways to Prevent Heroku Free Dyno From Sleeping

2 December 2017 aws lambda, heroku

Heroku offers free 550 dyno hours to all users. The free dyno, however, sleeps after 30 minutes of inactivity. This is really not ideal if you, like me, want to run a small free application for others to use without incurring too much cost. This poses a problem for me recently since I’ve been trying to use Heroku as an affordable and easy hosting for my low-volume Youtube-to-MP3 LINE bot.

Here are some of the ways you can prevent your Heroku dyno from sleeping.

New Relic APM Heroku Add-On

New Relic APM Heroku add-on Wayne tier is free. New Relic add-on will ping your application at an interval, preventing it from sleeping.

heroku addons:create newrelic:wayne

Pricing: Free plan is sufficient for basic usage.

Approximate time spent: 5 minutes

Pros: Easy to set up

Cons: -

Personal Review: I’ve used New Relic add-on with my Ellen Ticket Tracker a few years back and I remember it working just fine.

AWS Lambda

AWS Lambda is a serverless compute service, meaning you can run your code without having a backend server.

To keep Heroku dyno up, we can set up a lambda function to ping our service at a specific interval.

The ready-made canary-blueprint of AWS Lambda does just that. The official AWS Lambda Scheduled Event tutorial will take you through the inital process of setting up the function all the way to sending email notification. It took me about 10 minutes overall to setup and test it out.

Lambda Canary Template.

Lambda Canary Template.

Pricing: Free tier of AWS Lamba is 1 million requests. See pricing details here.

Approximate time spent: 10 minutes

Pros: Configurable ping rate, good introduction to AWS Lambda

Cons: Slightly move involved than using managed ping service like New Relic

Personal review: I use AWS Lambda for pinging my LINE bot application on Heroku. I highly recommend it. I like that I can configure exactly how frequent the ping will be as well as the url to ping. If configurability is what you’re looking for, AWS Lambda is the service for you.