Repository navigation
LAB 17 ‐ Object Storage: API Connectivity & Compute
Object Storage in Oracle Cloud Infrastructure (OCI) can be accessed not only via the Console but also programmatically using API/CLI from a Compute instance.
This approach is commonly used to upload backups, logs, or application data directly from servers to Object Storage.
In this method:
- A Compute Instance is used as a client
- Data is prepared on the server (e.g., compressed using
.taror.zip) - OCI CLI (API-based) is used to upload data
- Data is stored in Object Storage bucket
Compute Instance (Server) ↓ Prepare File (tar/zip) ↓ OCI CLI (API Call) ↓ Object Storage Bucket
- Login to Compute instance using PuTTY
- Convert data into archive file:
tar -cvf backup.tar /data
- Use OCI CLI to upload:
oci os object put --bucket-name my-bucket --file backup.tar
➡️ Backup is uploaded to Object Storage using API connectivity
- Compute Instance → Source of data
- OCI CLI → Acts as API interface
- Object Storage Bucket → Destination
- Archive File (.tar/.zip) → Backup format
- Automation (cron jobs, scripts)
- Faster for large data transfers
- No manual intervention required
- Suitable for production environments
You have application data on a server:
- Compress data into
backup.tar - Use CLI to upload to bucket
- Schedule daily backup using cron
- Automated backups
- Secure API-based transfer
- Scalable storage
- No manual upload required
Object Storage API connectivity using OCI CLI allows Compute instances to directly upload data to buckets, making it ideal for automated backups and real-time data transfer in production environments.
👉 “We can use OCI CLI from a compute instance to upload backup files to Object Storage using API calls, which helps in automation and real-time data transfer.”
In below screen, we want to upload scripts file to bucket. so, first we have to convert this file in .tar format(we have created a file scripts and inside that we have a file called random.txt)
Now first we convert the scripts folder to tar(zip) folder before sending to the object storage by using the below command.
tar -cvf scripts05052026.tar scripts
In the screen below, you will find four tar files, which serve as backups for the scripts.
Run this command to send file to bucket(here bucket name should be same as you have given in console ex. Test-bucket in my case)
oci os object put -bn Test-bucket --file scripts05052026.tar
However, we can observe an error indicating that the OCI command is not found.
Run below command to download OCI cli package
a)install Python 3 if not already installed:
sudo dnf install python3
press y to begin the installation
b)Install pip (Python package installer):
sudo dnf install python3-pip
press y to begin the installation
c)Install OCI CLI using pip:
python3 -m pip install oci-cli --upgrade
The OCI cli package has been successfully downloaded.
d)Verify the version:
oci --version
Again Run below command to send file in bucket
oci os object put -bn Test-bucket --file scripts05052026.tar
Say no to creating through browser.
We will create through CLI.
Always enter default location to save config file
Enter user's OCID
Enter tenancy's OCID
Enter default in below screen
write **default password (N/A) **
Open .oci folder
view config file using cat command
Ensure that all the details are accurate and match what you initially entered while creating the configuration file.
Use the cat command to view the API public key and copy it into Notepad for later use.
Now in OCI console navigate to the user section within the default domain under Identity & Security
The following screen will appear after adding the API key
You can now verify that all the details in the tab match the ones we entered while creating the configuration file in putty
The bucket is now successfully linked to the instance, allowing us to transfer the backup from the instance to the bucket.
Run below command to transfer file to bucket
oci os object put -bn Test-bucket --file scripts01012025.tar
As the user was an administrator, I had already created a policy to manage all resources in the tenancy.
However, if you encounter an error while uploading a file, it might be due to a lack of permissions. To address this, we created a policy that allows the user/group to manage objects in Compartment.
allow service objectstorage-us-ashburn-1 to manage object-family in compartment hub-compute-and-storage-compartment where target.bucket.name = 'Test-bucket'
Now as we can see, file is transferred in bucket successfully.