Can I get the exact region of my heroku app?

Viewed 641

My application on Heroku servers is located in the EU region. But that's all the info I get. The EU region has two locations: Ireland and Germany. I need to know in which of this region my app is located.

I can display some regions using heroku regions command but it's useless as it just shows me all available regions.

2 Answers

The output of the heroku info <APPNAME> heroku regions --json command can be used in combination with this AWS IP Ranges json information to figure out which exact region you're looking at.

When you run heroku info <APPNAME>, you will see the general region. But it's broad and not very useful.

For example, in this case, it's us

=== APPNAME
Auto Cert Mgmt: false
Dynos:          web: 1
Git URL:        https://git.heroku.com/APPNAME.git
Owner:          example@email.com
Region:         us
Repo Size:      0 B
Slug Size:      37 MB
Stack:          heroku-20
Web URL:        https://APPNAME.herokuapp.com/

If you look at the heroku regions info from heroku regions --json, you'll see there will be an entry where the "name" will match the "region" from heroku info.

Here, it's us-east-1

...
 {
    "country": "United States",
    "created_at": "2012-11-21T20:44:16Z",
    "description": "United States",
    "id": "59accabd-516d-4f0e-83e6-6e3757701145",
    "locale": "Virginia",
    "name": "us",
    "private_capable": false,
    "provider": {
      "name": "amazon-web-services",
      "region": "us-east-1"
    },
    "updated_at": "2016-08-09T22:03:28Z"
  },
...

From there, you can see the "provider" key in that region's json, and it'll show you the provider's name (likely AWS) and region (should be a more fine-grained region than the general heroku region).

Now you can take that region name, and look in the AWS IP Ranges JSON file for it -- that should give you the IPs that are associated with it. (Note, there will be many IP addresses associated)

Note that there will be many IP prefixes which have a matching region, because there are many IPs associated with it.

Here is one example of an entry which matches the us-east-1 region.

...
{
  "ip_prefix": "52.94.152.9/32",
  "region": "us-east-1",
  "service": "AMAZON",
  "network_border_group": "us-east-1"
},
...

You can use heroku info <APP-NAME> to find the Region ID. It will display some data like below.

=== APP-NAME
Addons:         heroku-postgresql:hobby-dev
Auto Cert Mgmt: false
Collaborators:  youremail@email.com
Dynos:          web: 1
Git URL:        https://git.heroku.com/appname.git
Owner:          appname@email.com
Region:         us
Repo Size:      0 B
Slug Size:      168 MB
Stack:          heroku-18
Web URL:        https://appname.herokuapp.com/

As you can see the Region ID is us. Then, you can use heroku regions command to find the regions belong to the ID.

ID         Location                 Runtime
─────────  ───────────────────────  ──────────────
eu         Europe                   Common Runtime
us         United States            Common Runtime
dublin     Dublin, Ireland          Private Spaces
frankfurt  Frankfurt, Germany       Private Spaces
oregon     Oregon, United States    Private Spaces
sydney     Sydney, Australia        Private Spaces
tokyo      Tokyo, Japan             Private Spaces
virginia   Virginia, United States  Private Spaces
Related