RDS IAM Database Authentication: Setup for PostgreSQL and MySQL, the rds-db:connect Policy, Tokens, RDS Proxy, Aurora, and "PAM Authentication Failed" Fixed

Logeshwaran
—

RDS IAM database authentication lets your application log in to Amazon RDS or Aurora (MySQL, MariaDB or PostgreSQL) with a short-lived token from IAM instead of a stored password. Four steps set it up: enable IAM authentication on the instance or cluster; create a database user mapped to IAM (PostgreSQL: CREATE USER app_user; GRANT rds_iam TO app_user;, MySQL: CREATE USER 'app_user' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';); allow rds-db:connect on arn:aws:rds-db:REGION:ACCOUNT:dbuser:DB_RESOURCE_ID/app_user in the app's IAM role; and connect with a token from aws rds generate-db-auth-token (or the SDK) as the password, over SSL. Tokens are valid for 15 minutes, but only for opening a connection; open connections keep working. The common errors, "PAM authentication failed for user" on PostgreSQL and "Access denied for user" on MySQL, almost always mean an expired token, a token made for a different hostname or user, a missing rds_iam grant, the wrong resource ID in the policy, or SSL turned off. Below: every step with commands, Python, Node.js and Java examples, RDS Proxy, Terraform, limits, cross-account access, and each error with its fix.

Jake's computer shop keeps its repair tickets in a small PostgreSQL database on Amazon RDS. For two years the ticket app logged in with a password in a config file, the same password three people knew and nobody had changed. When Ethan moved the app to Lambda, he took the chance to get rid of the password entirely. IAM authentication took an hour to set up and two more to debug, because one character in the policy ARN was wrong. This page is the hour, without the two.

⚡ Quick Answer

• Enable: aws rds modify-db-instance --db-instance-identifier mydb --enable-iam-database-authentication --apply-immediately. All steps.

• Database user: PostgreSQL GRANT rds_iam TO app_user;, MySQL IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS'.

• IAM: rds-db:connect on the dbuser ARN with the DB's resource ID. Policy.

• Connect: token as the password, SSL on, within 15 minutes. Code.

How it works · RDS Proxy · Terraform · Limits · Errors.

New to RDS? Our plain-English RDS explainer covers the basics, and the cards below cover the rest.

🧭 NEW HERE? READ THESE FIRST

New to RDS or AWS credentials? These five pages give you the background this one builds on:

📌 Bookmark this; the policy ARN format and the error table are the parts you will come back for.

How RDS IAM authentication works

With a normal database login, your database stores a password and checks it. With IAM authentication, your database trusts AWS instead:

  1. Your application, running with AWS credentials (a Lambda role, an EC2 instance role, your SSO login), asks for a database authentication token. You generate the token locally with the SDK or CLI, signed with those credentials; you do not need a network call to the database to create it.
  2. Your application connects to the database as an ordinary client, giving the token in place of the password, over an encrypted (SSL/TLS) connection.
  3. RDS checks the token's signature with IAM: is it valid, unexpired, for this database user, and does your identity have rds-db:connect permission for it?
  4. If so, your login succeeds, and your session works exactly like any other database session.

What you gain is real: no password for you to store, rotate or leak; access you control and audit through IAM like everything else; and access you can revoke by changing a policy. You can use it with RDS for MySQL, MariaDB and PostgreSQL and with Aurora MySQL and Aurora PostgreSQL. If you run RDS for SQL Server or Oracle, you use Kerberos (Active Directory) authentication instead.

IAM authentication or a password in Secrets Manager?

Both keep passwords out of your code. Which one fits you depends on how your app connects:

IAM database authenticationPassword in Secrets Manager
Password stored?None at allYes, encrypted, rotated on a schedule
What your app needsAn IAM role and an SDK call per connectionPermission to read the secret
EnginesMySQL, MariaDB, PostgreSQL (RDS and Aurora)All engines
Connection rateBest under about 200 new connections per secondNo special limit
Desktop and BI toolsAwkward: a fresh token per sessionEasy: a normal password
Extra costNoneA small monthly fee per secret, plus API calls

If your app already runs with a role on Lambda, ECS or EC2 and opens connections at a moderate rate, IAM authentication is the simpler, password-free choice. If you need very high connection rates, an engine without IAM support, or tools that cannot handle tokens, keep a password and let Secrets Manager rotate it; our Secrets Manager guide covers that route. Many teams use both: IAM for applications, a rotated password for the one reporting tool that cannot do tokens.

Jake: "So there's no password at all? How does the database know it's us?"

Ethan: "AWS vouches for us. The app shows a pass that AWS signed fifteen minutes ago, and the database checks the signature instead of a password."

Set it up: four steps

Step 1: enable IAM authentication on the database.

💻 Where to run these commands

Easiest: AWS CloudShell, nothing to install. Sign in to the AWS Management Console, choose your Region at the top right, then click the CloudShell icon (a small >_ terminal symbol) in the top bar, or type CloudShell in the search box and open it. When the $ prompt appears, paste a command and press Enter. CloudShell already has the AWS CLI, uses your console permissions and costs nothing extra.

On your own computer: install AWS CLI version 2 (installers for Windows, macOS and Linux are on the AWS CLI page), run aws configure once (or aws configure sso if your company signs in through single sign-on), and check it works with aws sts get-caller-identity. Then paste commands into Terminal on Mac or Linux, or PowerShell or Command Prompt on Windows.

Windows tip: a line ending in a backslash ( \ ) continues on the next line in CloudShell, Mac and Linux. In PowerShell use a backtick ( ` ) instead, in Command Prompt a caret ( ^ ), or simply join the lines into one. JSON inside single quotes works as shown in CloudShell; on Windows, save the JSON in a file and pass it as file://name.json.

Python examples: save the code in a file such as script.py, install the AWS SDK with pip install boto3, and run python script.py (python3 on Mac and Linux). It uses the same credentials as the AWS CLI; CloudShell has Python and boto3 ready.

Replace example values such as my-bucket, my-function, 111122223333 (an account ID) and us-east-1 with your own.

# RDS instance
aws rds modify-db-instance --db-instance-identifier tickets-db \
  --enable-iam-database-authentication --apply-immediately

# Aurora cluster
aws rds modify-db-cluster --db-cluster-identifier tickets-cluster \
  --enable-iam-database-authentication --apply-immediately

In the console, it is the Database authentication section of the instance's Modify page: choose "Password and IAM database authentication." Existing password logins keep working; IAM is added alongside.

Step 2: create a database user for IAM. Connect once with the master user and run:

-- PostgreSQL (RDS or Aurora)
CREATE USER app_user;
GRANT rds_iam TO app_user;
GRANT CONNECT ON DATABASE tickets TO app_user;
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA public TO app_user;

-- MySQL or MariaDB (RDS or Aurora)
CREATE USER 'app_user'@'%' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS';
GRANT SELECT, INSERT, UPDATE ON tickets.* TO 'app_user'@'%';

On PostgreSQL, a user with the rds_iam role can only log in with IAM tokens; password logins stop working for that user. Create a separate user for IAM rather than granting rds_iam to the master user.

Step 3: allow the IAM identity to connect. Covered in detail next, because the resource ARN is where most setups go wrong.

Step 4: connect with a token, over SSL. Covered in the connection section for the CLI, Python, Node.js and Java.

The IAM policy, and the resource ID trap

The permission is rds-db:connect, and its resource is a special ARN that names the database user:

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": "rds-db:connect",
    "Resource": "arn:aws:rds-db:us-east-1:111122223333:dbuser:db-ABCDEFGHIJKL01234567890XYZ/app_user"
  }]
}

Three details in that ARN cause most failures:

  • The service is rds-db, not rds.
  • The middle part is the resource ID, not the database name. It looks like db- followed by letters and digits for an instance, or cluster- followed by letters and digits for an Aurora cluster. Find it with aws rds describe-db-instances --db-instance-identifier tickets-db --query "DBInstances[0].DbiResourceId", or aws rds describe-db-clusters --query "DBClusters[0].DbClusterResourceId" for Aurora. Using tickets-db there is the single most common mistake.
  • The user name at the end must match the database user exactly, including case.

Attach the policy to whatever identity your app runs as: the Lambda execution role, the EC2 instance role, the ECS task role, or your own SSO role for testing. A wildcard such as dbuser:db-ABC.../* allows every database user on that instance; prefer naming the user.

Jake: "Which character was wrong in yours?"

Ethan: "I wrote the database's name where the resource ID goes. It looked completely reasonable and was completely wrong."

Connect with a token: CLI, Python, Node.js and Java

Download the RDS certificate bundle once, so clients can verify the server (global-bundle.pem from AWS's trust store), then generate a token and use it as the password.

From the command line (PostgreSQL):

HOST=tickets-db.abcdefghij12.us-east-1.rds.amazonaws.com
export PGPASSWORD="$(aws rds generate-db-auth-token --hostname $HOST --port 5432 --region us-east-1 --username app_user)"
psql "host=$HOST port=5432 dbname=tickets user=app_user sslmode=verify-full sslrootcert=global-bundle.pem"

From the command line (MySQL): the MySQL client must send the token in clear text inside the encrypted connection, so it needs one extra flag:

TOKEN="$(aws rds generate-db-auth-token --hostname $HOST --port 3306 --region us-east-1 --username app_user)"
mysql --host=$HOST --port=3306 --user=app_user --password="$TOKEN" \
  --enable-cleartext-plugin --ssl-ca=global-bundle.pem

Python (boto3 and psycopg2):

import boto3
import psycopg2

HOST = "tickets-db.abcdefghij12.us-east-1.rds.amazonaws.com"
rds = boto3.client("rds", region_name="us-east-1")

def connect():
    token = rds.generate_db_auth_token(DBHostname=HOST, Port=5432, DBUsername="app_user", Region="us-east-1")
    return psycopg2.connect(host=HOST, port=5432, dbname="tickets", user="app_user",
                            password=token, sslmode="verify-full", sslrootcert="global-bundle.pem")

with connect() as conn, conn.cursor() as cur:
    cur.execute("SELECT count(*) FROM tickets")
    print(cur.fetchone())

Node.js (AWS SDK v3 and the pg package):

import { Signer } from "@aws-sdk/rds-signer";
import pg from "pg";
import fs from "node:fs";

const host = "tickets-db.abcdefghij12.us-east-1.rds.amazonaws.com";
const signer = new Signer({ hostname: host, port: 5432, username: "app_user", region: "us-east-1" });

const client = new pg.Client({
  host, port: 5432, database: "tickets", user: "app_user",
  password: await signer.getAuthToken(),
  ssl: { ca: fs.readFileSync("global-bundle.pem").toString() },
});
await client.connect();
console.log((await client.query("SELECT count(*) FROM tickets")).rows);

Java and Spring Boot: the AWS Advanced JDBC Wrapper handles tokens for you with its IAM plugin, so the application configuration names a user and no password. With plain JDBC, generate the token with the SDK's RDS utilities and pass it as the password. In either case, configure the connection pool to create connections with a fresh token, because a pool that caches the first token fails 15 minutes later when it opens a new connection.

In a Spring Boot application.properties, the wrapper sits in front of the normal PostgreSQL (or MySQL) driver. Add the wrapper and the regular driver as dependencies, then:

spring.datasource.url=jdbc:aws-wrapper:postgresql://tickets-db.abcdefghij12.us-east-1.rds.amazonaws.com:5432/tickets?wrapperPlugins=iam&sslmode=verify-full
spring.datasource.username=app_user
spring.datasource.driver-class-name=software.amazon.jdbc.Driver

The iam plugin generates a token for each new connection with the application's AWS credentials (its role on ECS, EKS or EC2), so HikariCP, Spring Boot's default pool, never holds a stale token. There is a matching AWS Advanced Python Wrapper with the same IAM plugin for Python applications that would rather not call generate_db_auth_token themselves.

The token generation itself needs AWS credentials. If it fails with "could not load credentials" in Node.js, our SDK credentials guide covers that first problem.

Test your setup in five minutes

Before you change your application, prove each piece works from your own machine. If you test in this order, the first failing step tells you exactly where your problem is:

  1. Check that IAM auth is enabled: aws rds describe-db-instances --db-instance-identifier tickets-db --query "DBInstances[0].IAMDatabaseAuthenticationEnabled" should print true.
  2. Check your identity: aws sts get-caller-identity shows which role or user your token will be signed as. Make sure that identity has the rds-db:connect policy.
  3. Check the user exists with the right setup: as the master user, run \du app_user in psql and look for rds_iam in its roles (or SELECT user, plugin FROM mysql.user; on MySQL and look for AWSAuthenticationPlugin).
  4. Generate a token and connect with psql or mysql using the commands below, from a machine that can reach the database.
  5. Only then move to your code. If the command line works and your app does not, the difference is in your app: the hostname it generates the token for, its credentials, or its SSL settings.

You can run this test in five minutes, and it saves you hours of guessing inside application logs.

Tokens, expiry and connection pools

An authentication token is valid for 15 minutes, and it is only checked when a connection opens. That leads to three practical rules:

  • Generate a new token for each new connection, or at least every few minutes. Generating one is a fast local signing step, not a network call, so there is no reason to cache it long.
  • Open connections stay open past 15 minutes. A long-running session or a pooled connection is not cut off when its token expires; only new logins need a fresh token.
  • Connection pools need a token callback. Pools that take a fixed password at startup break after 15 minutes. Use the pool's hook for supplying the password per connection (for example, a password function in node-postgres, or the JDBC wrapper's IAM plugin), so each new connection gets a fresh token.

The token is tied to the hostname, port, Region and user it was generated for. A token made for the instance endpoint does not work against a cluster endpoint, a reader endpoint, a custom DNS name or an RDS Proxy endpoint, and vice versa: generate it for exactly the host you connect to.

Connecting from your laptop to a private database

Most production databases are not reachable from the internet, so you cannot connect from your laptop directly. The tidy way in is Session Manager port forwarding through an EC2 instance in the same VPC, with no SSH keys and no open inbound ports:

aws ssm start-session --target i-0123456789abcdef0 \
  --document-name AWS-StartPortForwardingSessionToRemoteHost \
  --parameters host=tickets-db.abcdefghij12.us-east-1.rds.amazonaws.com,portNumber=5432,localPortNumber=5432

While that runs, your laptop's port 5432 leads to the database. Two details trip people up here:

  • Generate the token for the real database hostname, not localhost. RDS checks the hostname inside the token, and it must be the database endpoint, even though your client connects to localhost.
  • Hostname verification fails through a tunnel, because the server's certificate names the database endpoint, not localhost. Use sslmode=verify-ca (checks the certificate chain but not the name) for this local session, or add the endpoint name to your hosts file pointing at 127.0.0.1 and keep verify-full.

Your own IAM identity needs rds-db:connect for the user you log in as, plus Session Manager permissions for the instance. Giving yourself a separate, read-only database user for this kind of access keeps your laptop sessions away from the application's write permissions.

Jake: "So even you can't just log in from home anymore?"

Ethan: "I can, through the tunnel, as a read-only user, with my own login. Which is exactly how it should have been all along."

IAM authentication from Lambda

Lambda is where IAM authentication shines: the function already has a role, so there is nothing to store at all. Add rds-db:connect to the execution role, put the function in the database's VPC with a security group the database allows on its port, and connect as above, creating the connection outside the handler so warm invocations reuse it.

Two Lambda-specific cautions. A sudden burst of new invocations means a burst of new connections, and IAM authentication is designed for moderate connection rates (see limits), so busy functions should sit behind RDS Proxy, covered next. And a timeout connecting (rather than an authentication error) is a network problem, not an IAM one; our Lambda to RDS timeout guide walks through it.

RDS Proxy with IAM authentication

RDS Proxy sits between your application and the database, pooling connections. With IAM authentication on the proxy, clients authenticate to the proxy with IAM tokens, and the proxy holds the pooled connections to the database.

  • In the proxy's settings, set client authentication to require IAM.
  • Give your application's role rds-db:connect on the proxy's resource: arn:aws:rds-db:REGION:ACCOUNT:dbuser:prx-PROXY_RESOURCE_ID/app_user, using the proxy's resource ID (it starts with prx-).
  • Generate the token for the proxy endpoint hostname, not the database's.
  • Configure how the proxy itself logs in to the database: traditionally with a Secrets Manager secret holding the database user's credentials, which the proxy reads with its own role.

This combination is the standard answer for serverless applications: IAM tokens for the app, connection pooling in the proxy, and no password in your code.

When a proxy setup fails, it fails at one of two hops, and it helps to test them separately. The first hop (application to proxy) fails with the same PAM or access-denied messages as a direct connection, and the causes are the same: a token generated for the database endpoint instead of the proxy's, a policy naming the database's db- resource ID instead of the proxy's prx- ID, or a client connecting without TLS, which IAM authentication to the proxy requires. The second hop (proxy to database) fails quietly from the application's point of view: connections hang or time out. Ask the proxy directly what it thinks of its targets:

aws rds describe-db-proxy-targets --db-proxy-name tickets-proxy \
  --query "Targets[].{Endpoint:Endpoint,State:TargetHealth.State,Reason:TargetHealth.Reason,Detail:TargetHealth.Description}" \
  --output table

A reason of AUTH_FAILURE means the proxy cannot log in to the database: the secret holds the wrong username or password, the proxy's IAM role lacks secretsmanager:GetSecretValue on the secret (and kms:Decrypt if the secret uses your own KMS key), or the password changed in the database but not in the secret. CONNECTION_FAILED or UNREACHABLE point at networking between the proxy's subnets and the database's security group. Fix the second hop first; the first hop cannot work until the proxy has healthy targets.

Terraform and CloudFormation

Terraform: enable IAM authentication with one argument, and build the policy ARN from the resource ID attribute so it is always right:

resource "aws_db_instance" "tickets" {
  identifier                          = "tickets-db"
  engine                              = "postgres"
  instance_class                      = "db.t4g.micro"
  allocated_storage                   = 20
  username                            = "postgres"
  manage_master_user_password         = true
  iam_database_authentication_enabled = true
  # ...
}

data "aws_iam_policy_document" "db_connect" {
  statement {
    actions   = ["rds-db:connect"]
    resources = ["arn:aws:rds-db:${var.region}:${data.aws_caller_identity.me.account_id}:dbuser:${aws_db_instance.tickets.resource_id}/app_user"]
  }
}

For Aurora, the same argument goes on aws_rds_cluster, and the cluster's cluster_resource_id attribute provides the cluster- ID. CloudFormation uses EnableIAMDatabaseAuthentication: true on the DB instance or cluster, and !GetAtt MyDB.DbiResourceId to build the ARN.

Creating the database user (GRANT rds_iam or AWSAuthenticationPlugin) happens inside the database, so neither tool does it on its own; run it once by hand, from a migration script, or with a database provider for Terraform.

Turning on iam_database_authentication_enabled on an existing database is a modification, not a replacement, and it does not restart the instance by itself; Terraform applies it with the next apply, or immediately if you also set apply_immediately = true. Check the result with the IAMDatabaseAuthenticationEnabled field from the CLI command in the section on finding your endpoint, since a plan that "succeeded" while a modification is still pending is a common reason the first IAM login fails.

Aurora specifics

If you run Aurora rather than a single RDS instance, the same steps apply with three differences:

  • Enable it on the cluster (modify-db-cluster), not on individual instances.
  • Use the cluster resource ID, which starts with cluster-, in the rds-db:connect ARN. One policy then covers the writer, the readers and any instance that joins later.
  • Generate the token for the endpoint you connect to: the cluster (writer) endpoint, the reader endpoint, or a custom endpoint. A token for the writer endpoint does not work on the reader endpoint. Our writer vs reader endpoint guide explains which to use when.

Aurora Serverless v2 supports IAM authentication the same way, which suits its pattern of scaling with demand: no password to distribute as your applications scale out.

Switching a live app from a password to IAM, without downtime

  1. Enable IAM authentication on the database. Password logins keep working, so nothing breaks.
  2. Create a new database user for IAM (for example, app_iam) with the same privileges as the current application user. Leave the old user alone for now.
  3. Add rds-db:connect for the new user to your application's role.
  4. Change your app to connect as the new user with a fresh token per connection, and deploy it to one instance or a canary first.
  5. Watch the connection logs until all connections arrive as the new user.
  6. Retire the password: lock or drop the old user, and delete the password from config files and secrets.

Because both logins work side by side during the switch, you can roll back at any point by redeploying the old version. Using a new user, rather than converting the old one, is what makes that rollback safe: on PostgreSQL, granting rds_iam to the old user would immediately stop its password from working.

Limits and when not to use IAM authentication

  • Connection rate. IAM authentication is recommended for workloads opening fewer than about 200 new IAM-authenticated connections per second. Above that, use connection pooling (RDS Proxy) or password authentication with Secrets Manager.
  • Engines. MySQL, MariaDB and PostgreSQL on RDS and Aurora. Not RDS for SQL Server, Oracle or Db2, which use directory-based authentication.
  • SSL is required. Clients that cannot use TLS cannot use IAM tokens.
  • Tools. Desktop clients and BI tools must be able to take a token as a password; most can, but each new session needs a fresh token, which is awkward for long-lived saved connections. Many teams keep a password user for such tools and IAM for applications.
  • Token tied to host. Every distinct endpoint needs its own token, as above. That includes custom DNS names: a token cannot be generated for your own Route 53 record (such as db.example.internal) that points at the instance; it has to be generated for the RDS endpoint itself.
  • Some policy conditions are ignored. IAM database authentication does not support several global condition keys, including aws:SourceIp, aws:SourceVpc, aws:SourceVpce, aws:VpcSourceIp, aws:Referer and aws:UserAgent. A policy that tries to limit rds-db:connect to an office IP range or a VPC endpoint will not behave as you expect; limit network access with security groups instead.
  • Token size. A token is generally about 1 KB and can be larger with many tags and long ARNs. Some ODBC drivers and desktop tools cap the password length and quietly cut the token short, which then fails as a generic authentication error.
  • Memory on the database. IAM authentication needs roughly 300 to 1,000 MiB of extra memory on the instance for reliable connections, which matters on small burstable instances; free that memory from buffers or caches, or pick a larger class.
  • Not with Kerberos on PostgreSQL. RDS for PostgreSQL cannot have IAM and Kerberos authentication enabled at the same time.
  • Not on Outposts. RDS on Outposts does not support IAM database authentication for any engine.
  • Temporary credentials must outlive the connect. If the token was signed with temporary credentials, those credentials must still be valid at the moment you connect, not only when you generated the token.

Seeing who connected

Once you have several roles connecting as different database users, you will want a record of who logged in and when. Your database's own logs do this best:

  • PostgreSQL: set log_connections to 1 in your DB parameter group, and export the PostgreSQL log to CloudWatch Logs from the instance's log export settings. Each successful login then shows the database user and client address.
  • MySQL: turn on the general log or, better for production, the audit plugin your engine version supports, and export it to CloudWatch Logs.

CloudTrail will not help here. Generating a token is a local signing step in the SDK or CLI, not an API call, so CloudTrail and CloudWatch do not record token generation or IAM database logins; the database's own logs are the record.

Because each application should log in as its own database user, tied to its own IAM role, these logs tell you which application connected, which your IAM policies then tie to a specific role. That link from a database session back to an AWS identity is one of the quieter benefits of moving off shared passwords.

Cross-account access

The rds-db:connect permission must be granted in the database's own account, so an application in another account cannot simply be given the permission there. The usual pattern:

  1. In the database account, create a role with rds-db:connect on the database user, whose trust policy allows the application's role from the other account to assume it.
  2. In the application account, allow the application's role to sts:AssumeRole on that role.
  3. In the application, assume the role first, then generate the token with the assumed role's credentials.
  4. Make sure the network path exists: VPC peering, Transit Gateway or PrivateLink between the accounts' VPCs, with security groups allowing the database port.

The token is signed with whatever credentials generated it, so it is the assumed role's identity that RDS checks.

Every IAM authentication error and its fix

ErrorCauseFix
PostgreSQL: PAM authentication failed for user "app_user"Token expired, made for another host or user, policy wrong, or IAM auth not enabledFresh token for the exact host; check the policy's resource ID and user; confirm IAM auth is on
PostgreSQL: password authentication failedUser lacks rds_iam, so the token is treated as a passwordGRANT rds_iam TO app_user;
MySQL: Access denied for user 'app_user'@'...' (using password: YES)User not created with AWSAuthenticationPlugin, token or policy problemRecreate the user with the plugin; check token host and policy
MySQL client: authentication plugin cannot be loaded, or cleartext disabledClient refuses to send the token--enable-cleartext-plugin (with SSL)
no pg_hba.conf entry ... no encryptionConnecting without SSLsslmode=verify-full with the RDS certificate bundle
Works for 15 minutes, then new connections failPool cached the first tokenSupply a fresh token per new connection
Works on the instance endpoint, fails on the proxy or cluster endpointToken generated for a different hostnameGenerate the token for the endpoint you connect to
Token generation fails: unable to locate credentialsNo AWS credentials where the app runsFix credentials first (role, profile, SSO)
MySQL: ERROR 1524 (HY000): Plugin 'AWSAuthenticationPlugin' is not loadedIAM database authentication is not enabled on this instance or cluster (or the engine version does not support it)Enable IAM authentication on the instance, then run the CREATE USER again
Master user's password stops working on PostgreSQLrds_iam was granted to the master user, and IAM now takes precedence over its passwordConnect with a token as that user and REVOKE rds_iam, or reset access through a different admin user
Connection times outNetwork: security group, subnet, public accessNot an IAM issue; see our RDS timeout guide

The PostgreSQL "PAM" error is frustratingly generic: it looks the same for an expired token, a wrong policy and a disabled feature. Work through it in order: is IAM authentication enabled on the instance; does the user have rds_iam; does the policy name rds-db:connect with the right resource ID and user; is the token fresh and generated for this exact host, port and user; and is SSL on? One of those five is nearly always the answer. For password-based login failures that are not about IAM, our Postgres authentication guide and MySQL 1045 guide cover the rest.

IAM logins for people: per-developer access and offboarding

IAM authentication is usually sold as a way to keep passwords out of applications, but it is just as useful for people. With IAM Identity Center, each developer signs in to AWS as themselves, and a permission set can include rds-db:connect on a database user, for example a read-only analyst user for the reporting team and a developer user for the engineers. To connect, they generate a token with their own SSO session and paste it into psql or their database tool as the password.

The benefit shows up the day someone leaves. Remove them from the Identity Center group and, within minutes, they can no longer generate tokens for the database; there is no shared password to change and no list of places it was copied to. Two details make this work properly:

  • Existing sessions stay open. The token is only checked when a connection is made, so a session that was already connected keeps working after access is removed. For a real offboarding, also end their open sessions in the database (in PostgreSQL, pg_terminate_backend on their connections).
  • Shared database users hide who did what. If ten people connect as developer, the database log shows developer ten times. Give each person, or at least each team, a separate database user if you need an audit trail, and remember that CloudTrail does not record IAM database logins.

A short helper script that generates the token and starts psql in one step makes this pleasant enough that people stop asking for a password:

HOST=tickets-db.abcdefghij12.us-east-1.rds.amazonaws.com
export PGPASSWORD="$(aws rds generate-db-auth-token --hostname $HOST --port 5432 --username analyst --region us-east-1 --profile tickets-sso)"
psql "host=$HOST port=5432 dbname=tickets user=analyst sslmode=verify-full sslrootcert=global-bundle.pem"

PostgreSQL: IAM users next to password users

IAM users and password users live side by side in the same database, and two PostgreSQL settings decide how the password side behaves. It helps to know them, because searches for one usually come from someone tightening security at the same time as adding IAM.

  • rds_iam wins for that user. Once a user has the rds_iam role, IAM takes precedence over password authentication for that user, the RDS master user included. That is why the switch-over section uses a new user: granting rds_iam to an existing user turns off its password on the spot. Keep the master user on a password (ideally managed in Secrets Manager) and give applications their own IAM users.
  • rds.accepted_password_auth_method controls which password methods the instance accepts for password users: md5+scram (the default, either method) or scram only. Its partner password_encryption controls how new passwords are stored. Both changes need a custom DB parameter group.
  • Move to SCRAM in the right order. Set password_encryption to scram-sha-256, reset each password user's password so it is stored the new way, check every role with the rds_tools.role_password_encryption_type() function (from the rds_tools extension), and only then switch rds.accepted_password_auth_method to SCRAM only. A role still holding an MD5 password cannot log in after the switch.

These settings govern password logins; IAM logins go through rds_iam and the token check instead. So a common, sensible end state is: applications on IAM, people and tools on SCRAM passwords from Secrets Manager, and MD5 turned off.

SQL Server, Oracle and Db2: what to use instead

"AWS RDS SQL Server authentication" is a common search from people who expected IAM authentication to work everywhere. It does not: IAM database authentication covers MySQL, MariaDB and PostgreSQL (on RDS and Aurora). The other engines have their own options:

  • RDS for SQL Server: SQL Server Authentication, the usual username and password logins, created as SQL logins, or Windows Authentication, where users sign in with their Active Directory accounts through Kerberos. For Windows Authentication, join the instance to AWS Directory Service for Microsoft Active Directory (AWS Managed Microsoft AD), which can also trust your own on-premises domain.
  • RDS for Oracle and RDS for Db2: password users, or Kerberos authentication through the same AWS Managed Microsoft AD.
  • Every engine: let RDS manage the master user's password in Secrets Manager, which rotates it and removes it from your config files, the closest equivalent to "no password in the app" when IAM authentication is not available.

For SQL Server applications that want something like IAM's benefits, the practical pattern is a dedicated SQL login per application whose password lives in Secrets Manager with rotation turned on, read by the application at startup through its IAM role. The database still sees a password, but no person ever handles it.

Where to find your RDS endpoint, username and password

Many people searching for RDS logins simply need the connection details. All of them except the password are in the console, on the database's page: the endpoint and port on the Connectivity & security tab, and the master username on the Configuration tab. The same details from the CLI:

aws rds describe-db-instances --db-instance-identifier tickets-db \
  --query "DBInstances[].{Endpoint:Endpoint.Address,Port:Endpoint.Port,User:MasterUsername,IAM:IAMDatabaseAuthenticationEnabled,Secret:MasterUserSecret.SecretArn}" \
  --output table

The IAM column shows whether IAM authentication is enabled at all, which answers the first question in the PAM error checklist. The password itself cannot be read back from RDS. If the Secret column shows an ARN, RDS manages the master password in Secrets Manager and you can retrieve it there (with permission); if it is empty and nobody remembers the password, you reset it, which takes effect without downtime. Our guide to resetting the RDS master password walks through both cases.

Frequently asked questions

What is RDS IAM database authentication?

A way to log in to RDS or Aurora MySQL, MariaDB and PostgreSQL with a short-lived token signed by IAM credentials instead of a stored password.

How do I enable IAM authentication on RDS?

Run aws rds modify-db-instance --enable-iam-database-authentication (or modify-db-cluster for Aurora), or choose password and IAM authentication in the console.

How do I create an IAM user in RDS PostgreSQL?

CREATE USER app_user; GRANT rds_iam TO app_user; then grant table permissions as usual.

How do I create an IAM user in RDS MySQL?

CREATE USER 'app_user'@'%' IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS'; then grant privileges.

What IAM permission is needed to connect?

rds-db:connect on arn:aws:rds-db:REGION:ACCOUNT:dbuser:RESOURCE_ID/USERNAME, where RESOURCE_ID starts with db- (instance) or cluster- (Aurora).

How long is an RDS IAM auth token valid?

15 minutes, for opening a connection. Connections already open keep working after the token expires.

How do I generate an RDS auth token?

aws rds generate-db-auth-token --hostname HOST --port PORT --region REGION --username USER, or the SDK equivalent such as boto3 generate_db_auth_token.

Why do I get "PAM authentication failed for user"?

The token is expired or for the wrong host or user, the policy's resource ID is wrong, or IAM authentication is not enabled. Check each in turn.

Is SSL required for RDS IAM authentication?

Yes. IAM authentication tokens must be sent over an encrypted connection.

Does RDS Proxy support IAM authentication?

Yes. Clients authenticate to the proxy with IAM tokens generated for the proxy endpoint, with rds-db:connect on the proxy's prx- resource ID.

What are the limits of RDS IAM authentication?

It suits fewer than about 200 new IAM connections per second, requires SSL, and supports MySQL, MariaDB and PostgreSQL engines only.

IAM authentication or Secrets Manager?

IAM auth needs no password at all and suits apps with IAM roles. Secrets Manager suits high connection rates, unsupported engines and tools that cannot use tokens.

How do I enable IAM auth in Terraform?

Set iam_database_authentication_enabled = true on aws_db_instance or aws_rds_cluster, and build the policy ARN from the resource_id attribute.

Can I use RDS IAM authentication across accounts?

Yes, by assuming a role in the database's account that has rds-db:connect, then generating the token with that role's credentials.

Does RDS for SQL Server support IAM authentication?

No. RDS for SQL Server and Oracle use Kerberos authentication with Active Directory instead.

What does rds.accepted_password_auth_method do?

It sets which password methods RDS for PostgreSQL accepts for password users: md5+scram (default) or scram only. Switch to scram only after every password has been reset under scram-sha-256. It does not apply to IAM logins.

Can I limit RDS IAM authentication to certain IP addresses?

Not with IAM conditions: aws:SourceIp, aws:SourceVpc and aws:SourceVpce are not supported for IAM database authentication. Use security groups and subnets to control where connections can come from.

Why is "Plugin 'AWSAuthenticationPlugin' is not loaded"?

IAM database authentication is not enabled on the MySQL instance or cluster. Enable it, then create the user with IDENTIFIED WITH AWSAuthenticationPlugin AS 'RDS'.

Does CloudTrail log RDS IAM authentication?

No. Token generation is local signing, so neither CloudTrail nor CloudWatch records it; use the database's connection logs to see who logged in.

Where do I find my RDS username and password?

The endpoint is on the Connectivity & security tab and the master username on the Configuration tab. The password cannot be shown: retrieve it from Secrets Manager if RDS manages it, or reset it.

How do I give developers IAM access to an RDS database?

Add rds-db:connect on a database user (for example a read-only analyst user) to their IAM Identity Center permission set. They generate a token with their own SSO profile and use it as the password; removing them from the group removes their ability to connect.

What happens to open connections when IAM database access is removed?

Nothing, at first: the token is checked only when a connection is made, so existing sessions keep running. End them in the database (pg_terminate_backend on PostgreSQL) as part of offboarding.

Why does RDS Proxy report AUTH_FAILURE for its target?

The proxy cannot log in to the database: the Secrets Manager secret has the wrong credentials, or the proxy's role cannot read the secret or decrypt it with its KMS key. Check with describe-db-proxy-targets.

Why does my app fail every 15 minutes?

The connection pool reuses the first token for new connections. Generate a fresh token for each new connection.

For readers preparing for an AWS certification

We have been covering AWS certifications alongside our fixes, so here is a short extra for readers studying for one. If you only came for the fix, you already have it; feel free to skip this part.

Exams that test this topic: Developer – Associate (DVA-C03 from December 1, 2026) • Security – Specialty (SCS-C03) • Solutions Architect – Associate (SAA-C03).

Here are the exam-style questions this topic tends to raise, with the reasoning you need to answer them:

1. A Lambda function must connect to RDS for PostgreSQL without storing any database password. What do you use?

IAM database authentication: an rds-db:connect permission on the function's role and a short-lived auth token as the password.

2. Which IAM action allows an identity to log in to an RDS database with IAM authentication?

rds-db:connect, on the dbuser ARN built from the database's resource ID and the user name.

3. How long is an RDS IAM authentication token valid for opening a connection?

15 minutes.

4. A serverless application opens many short-lived database connections. Which service pools them and supports IAM authentication?

Amazon RDS Proxy.

5. Which RDS engines support IAM database authentication?

MySQL, MariaDB and PostgreSQL, on RDS and Aurora.

6. A database password must be stored and rotated automatically for an engine without IAM authentication. Which service?

AWS Secrets Manager.

7. Engineers need to reach a private RDS database from their laptops without opening inbound ports. What can they use?

AWS Systems Manager Session Manager port forwarding through an instance in the VPC.

Exam codes and dates change often. Our AWS certification changes page keeps track of what is current.

πŸ“š ALSO READ

Where to go next, from other login errors to Lambda and RDS Proxy:

📌 Bookmark this; the policy ARN format and the error table are the parts you will come back for.

The ticket app now runs on Lambda with no password anywhere: not in the code, not in the config, not in three people's heads. The function's role carries rds-db:connect for one database user, and the old shared password was retired the same afternoon. Jake's only question was what happens if someone steals the Lambda code. "They get code," Ethan said. "No key comes with it. The pass is issued to the role, fresh every time, and it expires in fifteen minutes."

📌 If you keep one line from this page

Enable IAM auth on the instance, create the user with rds_iam (PostgreSQL) or AWSAuthenticationPlugin (MySQL), allow rds-db:connect on the dbuser ARN with the db- or cluster- resource ID, and connect over SSL with a fresh 15-minute token generated for the exact host.

PAM error = token, policy, grant or feature · MySQL needs --enable-cleartext-plugin · pools need a token per connection · under ~200 new connections per second.

Revision note. Written October 19, 2026. The safest password is the one that does not exist; the next safest expires in fifteen minutes.

Related