Generate Aurora DSQL auth tokens with Atlas
Aurora DSQL authenticates connections with short-lived IAM tokens rather than static passwords. Atlas can generate
those tokens in atlas.hcl with the aws_dsql_token data source and use them directly in your DSQL connection URL.
With this setup, Atlas generates the token at runtime from your environment configuration.
Before you start
You need:
- An Aurora DSQL cluster endpoint, for example
cluster-id.dsql.us-east-1.on.aws. - AWS credentials available to Atlas, either through environment variables, a shared profile, or an assumed role.
- IAM permission to connect. Use
dsql:DbConnectAdminfor the built-inadminrole, ordsql:DbConnectfor a custom database role. - Atlas installed and logged in if you are using Aurora DSQL support.
Generate an admin token
For the built-in admin role, set admin = true and embed the generated token in the dsql:// URL:
locals {
endpoint = "cluster-id.dsql.us-east-1.on.aws"
}
data "aws_dsql_token" "db" {
endpoint = local.endpoint
region = "us-east-1"
admin = true
}
env "dsql" {
url = "dsql://admin:${urlescape(data.aws_dsql_token.db)}@${local.endpoint}:5432/postgres?sslmode=require"
dev = "docker://dsql/16/dev"
}
The important parts are:
endpointis the Aurora DSQL cluster endpoint.regionis optional if your AWS configuration already sets a default region.admin = truetells Atlas to generate an admin auth token.urlescape()is required because the token contains characters that must be URL-encoded in the connection string.
With that in place, Atlas can generate the token at runtime:
atlas schema inspect --env dsql --config "file://atlas.hcl"
You can use the same environment for other commands too:
atlas migrate apply --env dsql --config "file://atlas.hcl"
Use a custom database role
If you do not want to connect as admin, create a database role with LOGIN, map your IAM identity to it, and let
Atlas generate a regular DSQL token.
CREATE ROLE atlas_migrations WITH LOGIN;
AWS IAM GRANT atlas_migrations TO 'arn:aws:iam::123456789012:role/AtlasDSQLConnect';
Grant whatever database privileges that role needs, then configure Atlas to use it:
locals {
endpoint = "cluster-id.dsql.us-east-1.on.aws"
username = "atlas_migrations"
}
data "aws_dsql_token" "db" {
endpoint = local.endpoint
region = "us-east-1"
}
env "dsql" {
url = "dsql://${local.username}:${urlescape(data.aws_dsql_token.db)}@${local.endpoint}:5432/postgres?sslmode=require"
}
When admin is omitted, Atlas generates a regular user token.
Use a profile or assume a role
aws_dsql_token can read credentials from a named AWS profile, and it can assume another IAM role before signing the
token:
data "aws_dsql_token" "db" {
endpoint = "cluster-id.dsql.us-east-1.on.aws"
region = "us-east-1"
profile = "prod"
role_arn = "arn:aws:iam::123456789012:role/AtlasDSQLConnect"
admin = true
}
Use profile when Atlas should load credentials from ~/.aws/config and ~/.aws/credentials. Use role_arn when
Atlas should assume a different IAM role before generating the token.