Skip to content

Deploying and running on Heroku

Ben edited this page Aug 1, 2020 · 3 revisions

This agent is designed to run as a small, self-contained app on Heroku. By default, it runs using free services and will keep your token up to date once set up correctly.

Configuration options

Instagram Token Agent is designed to be configured using Heroku's web UI or CLI. It understands the following environment variables:

Key Description Default
HIDE_HELP_PAGES Set to true to turn off the setup pages that aren't needed in production. none (Help pages display by default)
ALLOWED_DOMAINS White-list of the domains that can request the token via JS snippet or JSON object [YOUR_APP_NAME].herokuapp.com
REFRESH_MODE How should the refresh schedule work? Currently, only 'cron' is allowed, which refreshes on a set schedule cron
REFRESH_FREQUENCY How often should we refresh the token? Currently 'daily', 'weekly', 'monthly' are supported. weekly
JS_CONSTANT_NAME Set the name of the constant provided by the JS snippet InstagramToken

To set these options in the Heroku dashboard, click the 'Settings' tab in your app, then Reveal Config Vars.

What are all the moving parts?

This app is designed to run using free plans and add-ons at Heroku, and be configurable via Heroku's interface, so you don't need to use the CLI if you don't want to.

Here are the main parts and what they do:

  • Heroku free dyno: This serves the requests for tokens. Free dynos are limited in the amount of work they can do per month, but this should be ample for most sites just serving tokens.
  • Temporize Scheduler: This service schedules the app to refresh the token with Instagram to keep it working. Currently this happens once a week.
  • Heroku Postgres: The database that stores the token value
  • MemCachier: This caches the token payloads the agent sends out to keep things fast and take load off of the free dynos.

Considerations

Heroku's Free dynos will sleep after a period of inactivity, which means that there will be a short delay when someone requests a token for the first time in a while. This is usually pretty short: 2-5 seconds or so. If this is a problem, you can avoid this in a few ways:

  • Upgrade to a paid hobby dyno on Heroku: These are currently USD7/month and don't sleep, so they will respond quickly all the time. This is the simplest but most expensive option.
  • Put a CDN in front of your app: For example, KeyCDN can sit in front of the app on Heroku and respond very quickly to requests - this is a paid service, but would be a tiny cost.
  • Deploy the agent elsewhere: For example, deploying to AWS Elastic Beanstalk could be faster and less expensive than a paid Dyno at Heroku, but is more complex and needs more technical skills to set up.