Automation – Deploy DBCS in Oracle Cloud Infrastrucute using REST API

Share on:

I was working on automation using REST API (Representational State Transfer – Application Programming Interface) and found it very interesting and easy to implement with a simple command to deploy services on OCI (Oracle Cloud Infrastructure). In this blog, I will show you how to deploy DBCS (Oracle Database Cloud Service) using REST API.

I know you are thinking why I need to deploy using REST API if I have the console. You can schedule a job to stop/start DBCS and save costs. Especially when you doing any testing, auto stop/start will help, it will save time and money.

There are many ways to use APIs, I am using oci-curl function in this blog available by the OCI team. OCI_CURL will sign and encrypt your APIs so they are not sent in clear over the internet. OCI-CURL can be used on Linux and windows, I am using windows here.

You can use the below link to copy oci-curl script.

oci-curl

You only have to change these 4 parameters in this script as per your environment.

 

oci

 

Tenancy OCID, USER OCID, KeyFingerprint, and private key .pem file location. You can easily get it from the OCI console.

 

Pre-requisite:

  1. I am assuming you already have VCN (Virtual Cloud Network), subnet, security rules, and compartment
  2. Also, you need to generate a key pair using ssh-keygen so you can use the public key in JSON configuration file later

 

To Deploy the DB System we need below 4 things:

  1. OCI-CURL – I have it above
  2. API endpoint for the database: I used  database.ca-toronto-1.oraclecloud.com , if your cloud database is located somewhere else you can use that. full list here… API Endpoints
  3. Config File: I also need to create a small JSON file for a configuration containing information like availability domain, compartment id, db-related info, and public key to access the node
  4. DB System API command POST /20160918/DB systems

 

here is my JSON file here…

oci2

 

Now I have everything, so I just created a small shell script 

oci3

 

So to deploy the DB System, I just need to run the shell script like ./createdbsystem.sh and magically starts to begin 🙂 

Here is the output:

oci4

 

And when I go to the console, I can see its provisioning…

oci5

 

You can go to the work request to see how much was completed…

oci6

 

It will take like 20-30 mins to complete and then you can connect to the node using your private key.

Delete or terminating the DB System is, even more, simpler because you don’t need any configuration file, you need the OCID of the DB System.

Here is the script I created for termination…

oci7

Now we can schedule these jobs in crontab or windows scheduler to automate start/stop.

Share on:

More from this Author

oac

How to Import Custom Visualization in Oracle Analytics Cloud to See Images

In this blog, I will show you how to download and import the Image Gallery Plugin into OCI Oracle Analytics Cloud. using this plugin we can see ... Read More

Oracle 23c INTERVAL Data Type Aggregations

Analyze Invoices with Oracle Analytics and AI Document Understanding

OCI Document Understanding is an AI service that enables developers to extract text, tables, and other key data from document files through APIs and ... Read More

Back to Top