- Heroku Cookbook
- Mike Coutermarsh
- 677字
- 2021-08-05 17:14:28
Installing add-ons
Our application needs some additional functionality provided by an outside service. What should we do? In the past, this would have involved creating accounts, managing credentials, and maybe even bringing up servers and installing software. This whole process has been simplified by the Heroku add-on marketplace.
For any additional functionality that our application needs, our first stop should always be Heroku add-ons. Heroku has made attaching additional resources to our application a plug-and-play process. If we need an additional database, caching, or error logging, they can be set up with a single command.
In this recipe, we will learn the ins and outs of using the Heroku CLI to install and manage our application's add-ons.
How to do it...
To begin, let's open a terminal and navigate to one of our Heroku applications using the following steps:
- Let's start by taking a look at all of the available Heroku add-ons. We can do this with the
addons:list
command:$ heroku addons:list
There are so many add-ons that viewing them through the CLI is pretty difficult. For easier navigation and search, we should take a look at https://addons.heroku.com/.
- If we want to see the currently installed add-ons for our application, we can simply type the following:
$ heroku addons === load-tester-rails Configured Add-ons heroku-postgresql:dev HEROKU_POSTGRESQL_MAROON heroku-postgresql:hobby-dev HEROKU_POSTGRESQL_ONYX librato:development newrelic:stark
Note
Remember that for any command, we can always add
--app app_name
to specify the application. - Alternatively, our application's add-ons are also listed through the Heroku Dashboard available at https://dashboard.heroku.com.
- The installation of a new add-on is done with
addons:add
. Here, we are going to install the error logging service, Rollbar:$ heroku addons:add rollbar heroku addons:add rollbar Adding rollbar on load-tester-rails... done, v22 (free) Use `heroku addons:docs rollbar` to view documentation.
- We can quickly open up the documentation for an add-on with
addons:docs
:$ heroku addons:docs rollbar
- Removing an add-on is just as simple. We'll need to type our application name to confirm. For this example, our application is called
load-tester-rails
:$ heroku addons:remove rollbar ! WARNING: Destructive Action ! This command will affect the app: load-tester-rails ! To proceed, type "load-tester-rails" or re-run this command with --confirm load-tester-rails > load-tester-rails Removing rollbar on load-tester-rails... done, v23 (free)
- Each add-on comes with different tiers of service. Let's try upgrading our
rollbar
add-on to the starter tier:$ heroku addons:upgrade rollbar:starter Upgrading to rollbar:starter on load-tester-rails... done, v26 ($12/mo) Plan changed to starter Use `heroku addons:docs rollbar` to view documentation.
- Now, if we want, we can downgrade back to its original level with
addons:downgrade
:$ heroku addons:downgrade rollbar Downgrading to rollbar on load-tester-rails... done, v27 (free) Plan changed to free Use `heroku addons:docs rollbar` to view documentation.
- If we ever forget any of the commands, we can always use
help
to quickly see the documentation:$ heroku help addons
Note
Some add-ons might charge you money. Before continuing, let's double check that we only have the correct ones enabled, using the
$ heroku addons
command.
How it works…
Heroku has created a standardized process for all add-on providers to follow. This ensures a consistent experience when provisioning any add-ons for our application.
It starts when we request the creation of an add-on. Heroku sends an HTTP request to the provider, asking them to provision an instance of their service. The provider must then respond to Heroku with the connection details for their service in the form of environment variables. For example, if we were to provision Redis To Go, we will get back our connection details in a REDISTOGO_URL
variable:
REDISTOGO_URL: redis://user:pass@server.redistogo.com:9652
Heroku adds these variables to our application and restarts it. On restart, the variables are available for our application, and we can connect to the service using them. The specifics on how to connect using the variables will be in the add-ons documentation. Installation will depend on the specific language or framework we're using.
See also
- For details on creating our own add-ons, the process is well documented on Heroku's website at https://addons.heroku.com/provider
- Check out Kensa, the CLI to create Heroku add-ons, at https://github.com/heroku/kensa
- 機器人Python青少年編程開發實例
- Cassandra Data Modeling and Analysis
- Java程序設計
- 21天學通C++(第5版)
- Go語言底層原理剖析
- 零基礎學HTML+CSS
- Python開發基礎
- RESTful Web Clients:基于超媒體的可復用客戶端
- App Inventor少兒趣味編程動手做
- SignalR:Real-time Application Development(Second Edition)
- Clojure High Performance Programming(Second Edition)
- Data Manipulation with R(Second Edition)
- Clojure for Finance
- Less Web Development Cookbook
- 計算機系統解密:從理解計算機到編寫高效代碼