How to Get OCI Region and Instance Metadata from a Linux Server
When working with Oracle Cloud Infrastructure (OCI), there are times when you need to quickly fetch instance-level metadata — like the region, availability domain, shape, and other details — directly from the server. Fortunately, OCI exposes a handy metadata service that makes this easy to access from the command line.
In this post, I’ll show you how to pull just the region using curl, and also explain what other information is available if you query the full metadata endpoint.
Fetching the Region of an OCI Instance
To retrieve the region (like me-dubai-1) of an instance running on OCI, you can use:
curl -s http://169.254.169.254/opc/v1/instance/ | grep '"region":' | awk -F '"' '{print $4}'
[root@<Servername> <foldername>]# curl -s http://169.254.169.254/opc/v1/instance/ |grep region
"region": "me-dubai-1",
"regionInfo": {
"regionIdentifier": "me-dubai-1",
"regionKey": "DXB"
}
Another method to use is JQ
curl -s http://169.254.169.254/opc/v1/instance/ | jq -r '.region'
To get the complete instance metadata
Field | Description |
|---|---|
| The region where the instance is running |
| Availability Domain (e.g., |
| OCID of the compartment |
| Instance shape (e.g., |
| Name of the instance |
| Hostname of the instance |
| OCID of the instance |
| Instance lifecycle state (e.g., Running) |
Formatting JSON Output (Without jq)
If jq isn’t installed, you can still format the JSON nicely using Python:
curl -s http://169.254.169.254/opc/v1/instance/ | python3 -m json.tool
Notes:
The instance metadata service is local and does not require any credentials or internet access. It’s a super handy tool for automation scripts, configuration checks, or logging environment info in multi-region deployments.