DEV Community

leroykayanda
leroykayanda

Posted on

Connect to AWS RDS using IAM credentials

Ensure IAM authentication is enabled in RDS.

IAM Auth

Ensure the user that will connect to RDS has these permissions.

{
   "Version":"2012-10-17",
   "Statement":[
      {
         "Effect":"Allow",
         "Action":[
            "rds-db:connect"
         ],
         "Resource":[
            "arn:aws:rds-db:<region>:<account-id>:dbuser:<DBInstanceResourceID>/<DatabaseUser>"
         ]
      }
   ]
}
Enter fullscreen mode Exit fullscreen mode

Log in using the master user and create a DB user with the rds_iam role.

CREATE USER db_user;
GRANT rds_iam TO db_user;
Enter fullscreen mode Exit fullscreen mode

Generate a password valid for 15min.

aws rds generate-db-auth-token \
  --hostname <dn-hostname> \
  --port 5432 \
  --username db_user
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay