LAB 18 ‐ Object Storage: API Connectivity & Compute - gautam-amitesh/OCI GitHub Wiki
In Oracle Cloud Infrastructure we can add data to an OCI Object Storage bucket via the web interface or through the command line interface (CLI). While adding data to bucket via linux compute host we prefer to compress files which consume time and utilize CPU but when compressed (using gzip/bzip2 compression algorithm) it takes less storage so investing some time on higher compression ratio can save a lots of money in long-term storage.
-
Archiving vs. Compression
-
tar(Tape Archive): It does not compress files on its own. Its job is to glue multiple files and directories into a single file while preserving file permissions, directory structure, and metadata. -
gzip/bzip2: These are compression algorithms, but they can only compress one single file at a time also they don't know how to handle directories or preserve file trees.
-
When we run tar -cvf, we get a single big file that is the exact sum of the sizes of everything inside it but when we add compression flags like -z or -j then tar passes that single combined file through a compression tool.
-
Compression algorithms
-
Using
gzip(-z): Fast execution and lower CPU usage which is best for routine backups but results in comparatively larger output. Output file is in.tar.gzor.tgzextension.# Create a gzip-compressed archive tar -czvf destination-file_20260725.tar.gz source# Extract a gzip-compressed archive tar -xzvf source-file_20260725.tar.gz -
Using
bzip2(-j): Slower execution, higher CPU usage, and higher compression ratio which results in comparatively smaller files which is best for long-term storage wher saving disk space is more important than the extra time it takes to compress. Output file is in.tar.bz2or.tbz2extension.# Create a bzip2-compressed archive tar -cjvf destination-file_20260725.tar.bz2 source# Extract a bzip2-compressed archive tar -xjvf source-file_20260725.tar.bz2 -
Flag Summary for Reference:
-c: Create archive-x: Extract archive-z: Process throughgzip-j: Process throughbzip2-v: Verbose output (show progress)-f: Target file name follows immediately
-
Connect OCI Object Storage to Linux Compute Instance
Before moving forward we need to install and configure the OCI Command Line Interface (CLI)
OCI Command Line Interface (CLI) installation
-
For installing OCI CLI first install
pythonif not already installed (during installation, respond to the prompts for information)sudo dnf install python3 -
Install
pipwhich is package manager for Python (during installation, respond to the prompts for information)sudo dnf install python3-pip -
Now install
oci-cliusingpippython3 -m pip install oci-cli --upgrade -
Verify
oci-clipackage installationoci --version
OCI Command Line Interface (CLI) Configuration File Setup
-
To initiate
configsetupoci setup config -
It will ask you for the location to store
configfile and you will also see a default path is shown just hit enter to leave it as-is. -
Then it will ask you for user OCID which you can find it in OCI console
-
Click on the profile icon which you will see in the right corner of navigation bar
-
When you click on profile icon a menu will appear click on your
email/usershown on top of the menu -
Now it will navigate you to your profile details page from there you will see your
OCIDcopy it by clicking on copy button
-
-
Now it will ask you for tenancy OCID which you will find in tenancy details page
-
Click on the profile icon which you will see in the right corner of navigation bar
-
When you click on profile icon a menu will appear click on your
Tenancy:shown on third line of the menu -
Now it will navigate you to your tenancy details page from there you will see your
OCIDcopy it by clicking on copy button
-
-
Now it will ask you for region and to selecct you can simply choose the number next to it or you can manually type it. To know your exact region
-
In OCI console you will see your region written in the navigation bar click on it
-
From the dropdown click on
Manage regions -
It will navigate you to the Region management page here you will see you exact region name
-
-
Now it will ask you to generate a new API Signing RSA key pair, type
y -
Then it will ask you for the path where to store it leave it to default by hitting enter
-
Then it will ask you to enter name for your key leave it to default by hitting enter
-
Then it will ask you for passphrase for your private key if you don't want to create any passphrase just type
N/Aand hit enter then it will ask for repeating to confirm typeN/Aagain and hit enter -
Finally it all look like this
-
You can view config file to verify the details you provided
-
Now open your API public key in terminal and copy your key and keep it somewhere for future use
Setting Up API Key in OCI Console
-
Navigation
Profile > Identity domain: Default > User management > select user (eg. [email protected]) > API keys -
Click
Add API key -
Choose
Paste a public keyoption -
Now copy the public key you stored earlier and paste it here and click
Add -
Now it will show you
Fingerprintwhich you can match from the fingerprint you got when you createdconfigfile after verifying clickClose
Finally the bucket is successfully linked to our instance which allow us to transfer objects from the instance to the bucket.
Add Objects to Bucket from Instance
-
First we will create directory and then we will create some script file inside finally we will archive and compress it for testing bucket transfer
-
Now we will run OCI CLI command for adding object to bucket
oci os object put -bn <bucket-name> --file <object-name> -
To very the transfer check inside the particular bucket
-
Note: While trying to add the object inside bucket if you face lack of permission error. To resolve this error, copy the below policy that allows the user/group to manage objects in Compartment and modify it accordingly then paste it while creating the policy.
allow service objectstorage-us-ashburn-1 to manage object-family in compartment computecomp where target.bucket.name = 'Test-bucket'