Skip to content

LAB 18 ‐ Object Storage: API Connectivity & Compute

gautam-amitesh edited this page Oct 2, 2026 · 3 revisions

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.gz or .tgz extension.

      # 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.bz2 or .tbz2 extension.

      # 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 through gzip
      • -j: Process through bzip2
      • -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

  1. For installing OCI CLI first install python if not already installed (during installation, respond to the prompts for information)

    sudo dnf install python3
    
    image
  2. Install pip which is package manager for Python (during installation, respond to the prompts for information)

    sudo dnf install python3-pip
    
    image
  3. Now install oci-cli using pip

    python3 -m pip install oci-cli --upgrade
    
    image
  4. Verify oci-cli package installation

    oci --version
    
    image

OCI Command Line Interface (CLI) Configuration File Setup

  1. To initiate config setup

    oci setup config
    
    image
  2. It will ask you for the location to store config file and you will also see a default path is shown just hit enter to leave it as-is.

  3. 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

      image
    • When you click on profile icon a menu will appear click on your email/user shown on top of the menu

      image
    • Now it will navigate you to your profile details page from there you will see your OCID copy it by clicking on copy button

      image
  4. 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

      image
    • When you click on profile icon a menu will appear click on your Tenancy: shown on third line of the menu

      Screenshot 2026-07-25 181838
    • Now it will navigate you to your tenancy details page from there you will see your OCID copy it by clicking on copy button

      Screenshot 2026-07-25 182302
  5. 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

      image
    • From the dropdown click on Manage regions

      image
    • It will navigate you to the Region management page here you will see you exact region name

      image
  6. Now it will ask you to generate a new API Signing RSA key pair, type y

  7. Then it will ask you for the path where to store it leave it to default by hitting enter

  8. Then it will ask you to enter name for your key leave it to default by hitting enter

  9. Then it will ask you for passphrase for your private key if you don't want to create any passphrase just type N/A and hit enter then it will ask for repeating to confirm type N/A again and hit enter

  10. Finally it all look like this

    Screenshot 2026-07-25 184754
  11. You can view config file to verify the details you provided

    image
  12. Now open your API public key in terminal and copy your key and keep it somewhere for future use

    Screenshot 2026-07-25 185927

Setting Up API Key in OCI Console

  1. Navigation

    Profile > Identity domain: Default > User management > select user (eg. abc1234@gmail.com) > API keys
    
    image image image
  2. Click Add API key

    image
  3. Choose Paste a public key option

    image
  4. Now copy the public key you stored earlier and paste it here and click Add

    image
  5. Now it will show you Fingerprint which you can match from the fingerprint you got when you created config file after verifying click Close

    image

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

  1. 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

    image
  2. Now we will run OCI CLI command for adding object to bucket

    image
    oci os object put -bn <bucket-name> --file <object-name>
    
  3. To very the transfer check inside the particular bucket

    image

  • 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'
    

Clone this wiki locally