Oracle RDS Connect to an EC2 compute resource

When using the RDS Console to provision an Oracle RDS database we are given the option under Connectivity to ‘Connect to an EC2 compute resource’

This short blog will explore utilising the Connect to an EC2 compute resource option

Step 1: Provision an EC2 Instance and install the Oracle Client

  • Navigate to the EC2 Console and Select Launch instance

We will use the below options

OptionValue
Namerdsconnect01
Amazon Machine Image (AMI)Amazon Linux, Free Tier eligible
Architecture64-bit (x86)
Instance typet2.micro, Free Tier eligible
Key pair (login)Create new key pair
Key pair name: rdsconnect01
Key pair type: RSA
Private key file format: .pem
Create key pair
Network settingsreview : vpc, subnet, public IP
accept defaults or change if needed
Create security groupAllow SSH traffic from 0.0.0.0/0 (public), can restrict if needed but this is just a test
Configure storagechange default root volume
1 x 50 GiB gp3
Advanced detailsIgnore

EC2 will take 5 Minutes to create

Once EC2 has been provisioned select Server on EC2 Console and connect

Step 2 : Install Oracle Client

Open a web browser and goto : Instant Client for Linux x86-64 (64-bit)

Choose the Latest 19.x and Basic Package (RPM), copy the download url such as :

https://download.oracle.com/otn_software/linux/instantclient/1926000/oracle-instantclient19.26-basic-19.26.0.0.0-1.x86_64.rpm

On the EC2 use the above URL to download the file to the host

you will be logged in as ec2-user in home directory /home/ec2-user

curl -O https://download.oracle.com/otn_software/linux/instantclient/1926000/oracle-instantclient19.26-basic-19.26.0.0.0-1.x86_64.rpm

curl -O https://download.oracle.com/otn_software/linux/instantclient/1926000/oracle-instantclient19.26-sqlplus-19.26.0.0.0-1.x86_64.rpm
sudo yum install oracle-instantclient19.26-basic-19.26.0.0.0-1.x86_64.rpm
sudo yum install oracle-instantclient19.26-sqlplus-19.26.0.0.0-1.x86_64.rpm

If we need add the below to our path we can run sqlplus, not the version is in the path so if you downloaded a different version of the rpm your path will be different

export PATH=/usr/lib/oracle/19.26/client64/bin:$PATH

Step 3: Provision and Oracle RDS database and connect to an EC2 resource

Navigate to the RDS Console and use below options

OptionValue
Choose a database creation methodStandard create
Engine typeOracle
Database management typeAmazon RDS
EditionOracle Standard Edition Two
LicenseLicense Included
Engine versionUse Latest (default)
TemplatesDev/Test
SettingsAccept Defaults
Credentials SettingsAccept Defaults
Instance configurationBurstable classes (includes t classes)
db.t3.small
StorageAccept Defaults
Availability & durabilityDo not create a standby instance
ConnectivityConnect to an EC2 compute resource
EC2 instancerdsconnect01 (The instance we created above)
DB Subnet, Public access, Security GroupAccept Defaults
Tagsskip
Database authenticationAccept Defaults
Monitoring Accept Defaults
Additional configurationInitial database name : ORCL
DB parameter group, Option group
, Character set
Accept Defaults
BackupAccept Defaults
EncryptionAccept Defaults
MaintenanceAccept Defaults

Database will take 10 Minutes to create

Step 4: Obtain admin password

While Database is creating we choose to store the admin password in AWS Secret Manager, navigate to Secret Manager Console > Secrets > select Secret name rds<random hash>

Click on the URL then Retrieve secret value and copy the password to be used to test connectivity

Step 5 : Test connectivity from the EC2 to Oracle RDS database

From the RDS Console select our database we have created and select ‘Connectivity & security’, make a note of :

  • Endpoint
  • Port (should be 1521 default)

Next Navigate to ‘Configuration’ make a note of:

  • DB name (should be ORCL)

using this information we can form our database connection string which has a format of:

  • //host[:port][/service_name]
  • as an example : //database-1.cekqbdsf234u.eu-west-2.rds.amazonaws.com:1521/ORCL

ensure path env variable is set to use sqlplus (mentioned above in Step 2)

Now using the username (admin) + password (in secret manager) + connection string we can test a connect to the database as below:

sqlplus admin/'<password encased with single quotes>’@////host[:port][/service_name]:1521/ORCL

(I’ve blacked out some of IP, Password, Endpoint for security)