DEV Community

Faris Durrani
Faris Durrani

Posted on

How to retrieve the OCI instance ID from within itself

How to retrieve the OCID of a compute instance in Oracle Cloud from within itself using Instance Metadata (Bash and Python)

Using Bash

INSTANCE_ID=$(curl -s -H "Authorization: Bearer Oracle" http://169.254.169.254/opc/v2/instance/ | jq -r '.id')
Enter fullscreen mode Exit fullscreen mode

Using Python

import requests

instance_id = requests.get(
    "http://169.254.169.254/opc/v2/instance/",
    headers={"Authorization": "Bearer Oracle"},
).json()["id"]
Enter fullscreen mode Exit fullscreen mode

References

  1. Oracle: Getting Instance Metadata

Safe harbor statement

The information provided on this channel/article/story is solely intended for informational purposes and cannot be used as a part of any contractual agreement. The content does not guarantee the delivery of any material, code, or functionality, and should not be the sole basis for making purchasing decisions. The postings on this site are my own and do not necessarily reflect the views or work of Oracle or Mythics, LLC.

This work is licensed under a Creative Commons Attribution 4.0 International License.

Top comments (0)