22_Object_Storage_To_Instance_Through_API connectivity - Nirvan-Pandey/OCI_DOC GitHub Wiki
22_1: Overview
The purpose of API connectivity between Object Storage and a Compute instance in Oracle Cloud Infrastructure (OCI) is to demonstrate how to securely and efficiently interact with Object Storage from a Compute instance using APIs. This typically covers:
Key Objectives:
-
Understanding API Connectivity: Learn how to set up and use API keys for secure authentication and authorization.
-
Installing and Configuring OCI CLI: Install the OCI CLI on a Compute instance and configure it with the necessary credentials.
-
Interacting with Object Storage: Use the OCI CLI or SDKs to perform operations such as uploading, downloading, and managing objects in Object Storage.
-
Automating Tasks: Automate common tasks like data backup, retrieval, and management using scripts and API calls.
-
Example Use Cases:
- Data Backup: Automate the process of backing up data from a Compute instance to Object Storage.
- Data Retrieval: Retrieve and process data stored in Object Storage from a Compute instance.
- Integration: Integrate Object Storage with applications running on Compute instances for scalable storage solutions.
22_2: Prerequisites for Operations
- Create a New User and Group:
Avoid using the root user for regular operations. Creating a new user and group follows the principle of least privilege, reducing the risk of accidental or malicious changes.
This allows you to grant specific permissions and manage access more effectively.
Separating duties between users and groups helps maintain a secure and organized environment.
Please note as of now, we are using the tenancy user.
- OCI CLI Installation:
Install the OCI CLI on your Compute instance.
22_2: Create a New User and Group
Step1: Navigation
Navigate to BurgerMenu-->Identity & Security-->Domains-->Default Domains-->Groups-->Click Create
Step2: Create a group.
Step3: Assign the user to this group. User is added to this group.
22_3: OCI CLI Installation
The Oracle Cloud Infrastructure (OCI) Command Line Interface (CLI) is a tool that allows you to interact with OCI services from the command line, enabling automation and efficient management of cloud resources.
Step1: Login to the instance
Step2: Execute command
sudo dnf install python36-oci-cli
Step3: Write y to begin the installation.
Step4: The OCI cli package has been successfully downloaded.
Step5: Run below command to check version of installed OCI cli package.
oci cli -v
22_4: Setting up data
The Oracle Cloud Infrastructure (OCI) Command Line Interface (CLI) allows you to automate the process of pushing data to OCI services. By scripting OCI CLI commands, you can set up workflows that automatically handle tasks such as uploading data to Object Storage or provisioning resources. We will push data through the CLI, and the CLI will automatically guide the steps to complete the tasks.
Step1: Creating a test file.
We will create a test file in /tmp folder and will upload this file to OCI.
cd /tmp
touch sample.txt
ls -lrth
Step2: Executing the upload command
Generic Command
oci os object put -bn bucket_name --file file_name
Edited Command
oci os object put -bn Test_Bucket --file sample.txt
Step3: Write y to continue.
It failed to find config file,so asking to create new.
Step4: Say no to creating through browser.
We will create through CLI.
Step5: Keep the location intact.
It is asking a location for config file. We will not fill this as standard practice is to keep the file at default location i.e. /root/.oci/config
Step6: Fill the OCI ID.
We will copy the OCI ID of the Backup User and paste here.
Step7: Fill the tenancy id.
The tenancy id of the user created.
Step8: Enter the region.
Step9: Fingerprint is gerenated
I choose passphrase N/A.
Step10: Use the cat command to view the API public key and copy it into Notepad for later use.
cat /root/.oci/config
Step11: Again we will try to upload.
oci os object put -bn Test_Bucket --file sample.txt
Error occurred.
Error: Unable to retrieve namespace internally. Please provide the namespace using the option "--['namespace']".
Step12: Troubleshooting the Error.
Reason Suspected: API Key not attached to the user.
We will upload the API key by pasting the public key which we copied.
Navigate to the user
Identity->Domains-->DefaultDomain-->User-->API Key-->Add ApI Key
The bucket is now successfully linked to the instance, allowing us to transfer the backup from the instance to the bucket. Run below command again to transfer file to bucket
oci os object put -bn Test_Bucket --file sample.txt
Error: Unable to retrieve namespace internally. Please provide the namespace using the option "--['namespace']".
Step13: Troubleshooting the Error Again.
Reason Suspected: Policy not assigned.
Step14: Fresh error occurred,
Troubleshoot the policy again and edit the policy
Since my user was administrator, thats why policy and instances were not able to communicate. Allowing the administrator group to manage object in Compute in the policy.
Allow group Administrators to manage object-family in compartment NP_Compute
Again pushed the command to the object and it was successful.