A few days ago, Oracle Cloud opened free account registration allowing lifetime usage of:
- 2 compute VMs (1 OCPU, 1GB RAM each)
- 2 autonomous databases
- Storage, load balancer, and more services
Of course, I registered immediately and chose Korea as the main region for faster access from Shanghai.
Since the Korean region quickly ran out of capacity (Out of host capacity
), I explored ways to automate server creation using APIs and oci-cli
. This post documents how to use OCI CLI to script the automatic creation of servers.
Environment: I used CentOS. Ubuntu users may need to adapt paths or commands accordingly.
Requirements
- Mobile phone (for verification)
- Credit card
Initially, one credit card could register multiple accounts, but that was quickly abused. Now it’s one card per account, and many Chinese cards are restricted.
Free Resources Received
- 2 Autonomous Databases (each with 1 OCPU, 20 GB storage)
- 2 Compute VMs (1/8 OCPU, 1 GB RAM)
- 2 Block Volumes (100 GB total, 5 free backups)
- 10 GB Object Storage and Archive Storage
- 1 Load Balancer (10 Mbps)
- 10 TB/month outbound data
- 500 million ingest datapoints and 1 billion monitoring datapoints
- 1 million notifications and 1,000 emails per month
Main Steps
- Register Oracle Cloud account
- Create the first server and record required info
- Install
oci-cli
- Configure CLI and add API keys
- Automate server creation with CLI
- Automate ARM server creation using Python
1. Register Oracle Cloud Account
Go to Oracle Cloud Free Tier and follow the steps:
- Address
- Phone number (for verification)
- Credit card (charged for verification, refunded later)
Use a Gmail account if possible. A U.S. address worked for me.
2. Create the First Server and Record Info
Use Chrome DevTools to inspect the instances
network request during server creation. Record the following:
availabilityDomain
compartmentId
subnetId
shape
(e.g.,VM.Standard.E2.1.Micro
)ssh_authorized_keys
imageId
Also get:
- User OCID
- Tenancy OCID
3. Install oci-cli
Run:
bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"
Verify installation:
oci -v
4. Configure CLI and Add API Key
Run:
oci setup config
Upload the generated public key to your user profile in Oracle Cloud Console.
Test with:
oci iam availability-domain list
If no error, configuration succeeded.
5. Automate Server Creation Using CLI
Use the following command, replacing placeholders with your values:
oci compute instance launch
--availability-domain JCbl:AP-SEOUL-1-AD-1
--display-name seoul1
--image-id ocid1.image.oc1.ap-seoul-1.aaaa...
--subnet-id ocid1.subnet.oc1.ap-seoul-1.aaaa...
--shape VM.Standard.E2.1.Micro
--assign-public-ip true
--metadata '{"ssh_authorized_keys": "ssh-rsa AAAAB3..."}'
--compartment-id ocid1.tenancy.oc1...
You can write this into a script oci.sh
and set up a cron job:
# /root/oci.sh
oci compute instance launch --availability-domain ... # same as above
Cron job:
crontab -e
* * * * * /bin/bash /root/oci.sh >> /root/oracle.log 2>&1
Optional for debugging:
tail -F /root/oracle.log
If there’s no available capacity, you’ll see:
"message": "Out of host capacity.",
"status": 500
Ignore and let it keep trying.
6. Automate ARM Server Creation Using Python
Oracle recently added ARM servers:
- 4 Ampere A1 cores
- 24 GB RAM
- Can be split into up to 4 VMs
Use the following Python script to automate:
#!/usr/bin/env python3
from subprocess import Popen, PIPE
import time
cmd = '''
oci compute instance launch
--availability-domain NFWU:AP-TOKYO-1-AD-1
--display-name ja_arm
--image-id ocid1.image.oc1.ap-tokyo-1.aaaa...
--subnet-id ocid1.subnet.oc1.ap-tokyo-1.aaaa...
--shape VM.Standard.A1.Flex
--assign-public-ip false
--compartment-id ocid1.tenancy.oc1..aaaa...
--shape-config '{"ocpus":4,"memory_in_gbs":24,"local_disks":200}'
--metadata '{"ssh_authorized_keys": "ssh-rsa AAAAB3..."}'
'''
while True:
proc = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE, encoding="utf-8")
out, err = proc.communicate()
if 'LimitExceeded' in err:
print("Configuration failed or instance already created.")
break
time.sleep(10)
Once successful, add IPv4/IPv6 manually.