Created
December 9, 2024 15:26
-
-
Save alexdebrie/4dcad46d603e865a92f1d097b08f2b41 to your computer and use it in GitHub Desktop.
PSQL to DSQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dsql { | |
local auth_token | |
auth_token=$(aws dsql generate-db-connect-admin-auth-token \ | |
--region us-east-1 \ | |
--expires-in 3600 \ | |
--hostname CLUSTER_ENDPOINT_URL) || { echo "Failed to generate auth token" >&2; return 1; } | |
if [ -z "$auth_token" ]; then | |
echo "Auth token is empty" >&2 | |
return 1 | |
fi | |
PGPASSWORD="$auth_token" PGSSLMODE=require psql \ | |
--dbname postgres \ | |
--username admin \ | |
--host CLUSTER_ENDPOINT_URL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Throw this in your ~/.zshrc (or relevant shell config file) to easily connect to your DSQL instance with PSQL. It will grab an authentication token and use that to connect.
Be sure to replace 'CLUSTER_ENDPOINT_URL' with your actual endpoint URL.
If you need a certain AWS profile, set AWS_PROFILE= before
aws dsql ...
on line 3.Adopted from the SQL client connection docs page here.