Generating Heroku App Inventory Lists (CSV) using Python/Pandas

Many businesses need to leave PAAS vendors like Heroku after a while. It's nice to have a list of all the moving parts as part of any migration plan. Here's a quick script to generate one:

When migrating thousands of containers across dozens of teams to Kubernetes or Dockerized environments, it can really help to have an inventory list which describes all the running services on all slugs in the ecosystem. Here's a python script that will do just that:

import requests

import pandas as pd

import csv

 

API_KEY = 'HRKU-API-Token' #get a token from your user profile settings

team_ids = ['dev-test-team’, ‘any-number-of-teams-here-comma-separated’]

 

all_apps_data = []

headers = {

    "Accept": "application/vnd.heroku+json; version=3",

    "Authorization": f"Bearer {API_KEY}",

}

 

# Loop through each team ID and fetch config data

for team_id in team_ids:

    response = requests.get(f'https://api.heroku.com/teams/{team_id}/apps', headers=headers)

    apps = response.json()

    for app in apps:

        app_id = app['id']

        response = requests.get(f'https://api.heroku.com/apps/{app_id}/dynos', headers=headers)

        dynos = response.json()

        response = requests.get(f'https://api.heroku.com/apps/{app_id}/addons', headers=headers)

        addons = response.json()

        for dyno in dynos:

            dyno_data = {

                'app_id': app_id,

                'app_name': app['name'],

                'dyno_id': dyno['id'],

                'dyno_size': dyno['size'],

                'dyno_type': dyno['type'],

                'addons': ', '.join([f"{addon['name']} ({addon['plan']['name']})" for addon in addons]),

            }

            all_apps_data.append(dyno_data)

 

#organize data

df = pd.DataFrame(all_apps_data)

df.to_csv('heroku_apps_data.csv', index=False)

Output is in this format (CSV):

app_id

app_name

dyno_id

dyno_size

dyno_type

addons

UUID

Name01

dyno_UUID

Basic

proc_name0

postgresql-metric-NUM (heroku-postgresql:PLAN), redis-silhouetted-NUM (heroku-redis:PLAN)

UUID

Name01

dyno_UUID

Basic

web

postgresql-metric-NUM (heroku-postgresql:PLAN), redis-silhouetted-NUM (heroku-redis:PLAN)

UUID

Name02

dyno_UUID

Basic

web

postgresql-metric-NUM (heroku-postgresql:PLAN), redis-silhouetted-NUM (heroku-redis:PLAN)

UUID

Name02

dyno_UUID

Basic

proc_name0

postgresql-metric-NUM (heroku-postgresql:PLAN), redis-silhouetted-NUM (heroku-redis:PLAN)

If you're looking to migrate from Heroku into AKS, GKE, EKS, or some other Kubernetes solution, we've got your back. Reach out to talk to our certified experts for your next cloud migration project.

Last updated