mgalardini
mgalardini

Reputation: 1467

Change Dyno types through the Heroku API

I have an app running in Heroku; I'm using the Heroku scheduler to run a python script that scales the number of dynos at particular times of the day, using the python API (following this answer):

import heroku
cloud = heroku.from_key(os.environ.get('HEROKU_API_KEY'))
app = cloud.apps['myapp']
webproc = app.processes['web']
webproc.scale(1)

My question is: is there an API call to change Dyno types? For instance to change it from "standard 1X" to "standard 2X" or to "hobby".

Thanks

Upvotes: 1

Views: 847

Answers (2)

qff
qff

Reputation: 5902

Not via the Python API (which is deprecated), but via the regular HTTP API you can do:

requests.patch(
    f"https://api.heroku.com/apps/{APP_ID_OR_NAME}/formation",
    json={"updates": [{"size": DYNO_TYPE, "type": "web"}]},
    headers={
        "Content-Type": "application/json",
        "Accept": "application/vnd.heroku+json; version=3",
        "Authorization": f"Bearer {TOKEN}",
    },
)

Here using the requests-library.

I believe the dyno size update applies to all process types -- here I've only list web -- at least when going from e.g. "free" to "hobby". Otherwise, you simply add those other process types to the updates-list.

See Heroku API docs: https://devcenter.heroku.com/articles/platform-api-reference#formation-batch-update

Upvotes: 1

mgalardini
mgalardini

Reputation: 1467

A chat with the Heroku support has confirmed that the python API has no command to perform this operation; I have therefore resorted to add the following script to the app (following this answer):

#!/bin/bash

curl -s https://s3.amazonaws.com/assets.heroku.com/heroku-client/heroku-client.tgz | tar xz
mv heroku-client/* .
rmdir heroku-client
PATH="bin:$PATH"

heroku dyno:type hobby --app MYAPP

Changing hobby with standard-1x or standard-2x as needed.

Upvotes: 0

Related Questions