Open database connection to AWS RDS with IAM

Version 1.0.0 (2.51 KB) by Jeff Mandel
A maven pom file to download the requisite jars to enable a connection to an AWS database
1 Download
Updated 8 Mar 2025

View License

When developing a microservice that accesses an AWS RDS database, securing the connection with IAM is useful. Amazon provides a driver wrapper that adds the authentication methods, but it requires a number of jars on the classpath. This project provides a Maven pom that downloads all of these so they can be added to the static javaclasspath.
Usage:
  1. copy the file pom.xml to a directory and cd to the directory
  2. mvn dependency:copy-dependencies (This will download all of the jars to the directory target/dependency)
  3. find "$(cd target/dependency;pwd)" -type f > $(matlab -batch "fprintf('%s', fullfile(prefdir,'javaclasspath.txt'))") (This gets a listing of all files in that directory and writes it to a file. The filename is generated by calling matlab to get the prefdir location)
  4. start matlab and call openRDSdb.m, supplying credentials directly, or by specifying an AWS profile.
I've tested this on Mac and Linux. It should work on Windows if you have Maven installed and can figure out how to make step 3 work in Windows. Note that in a production environment (meaning deploying a Docker container on AWS), you should attach a policy to the service that grants the service permission to access the database, but during development using a profile is useful.

Cite As

Jeff Mandel (2025). Open database connection to AWS RDS with IAM (https://www.mathworks.com/matlabcentral/fileexchange/180330-open-database-connection-to-aws-rds-with-iam), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2024b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0