Securely connect to Lightsail PostgreSQL databases with SSL
Amazon Lightsail creates an SSL certificate, and installs it on your PostgreSQL (Postgres) managed database when it’s provisioned. The certificate is signed by a certificate authority (CA), and it includes the database endpoint as the Common Name (CN) for the SSL certificate to guard against spoofing attacks.
An SSL certificate created by Lightsail is the trusted root entity and should work in most cases but might fail if your application does not accept certificate chains. If your application does not accept certificate chains, you might need to use an intermediate certificate to connect to your AWS Region.
For more information about the CA certificates for your managed database, supported AWS Regions, and how you can download intermediate certificates for your applications, see Download an SSL certificate for your managed database.
Prerequisites
-
Install PostgreSQL server on the computer you will use to connect to your database. For more information, see PostgreSQL Downloads
in the Postgres website -
Download the appropriate certificate for your database. For information, see Download an SSL certificate for your managed database.
Connect to your Postgres database using SSL
Complete the following steps to connect to your Postgres database using SSL.
-
Open a Terminal or Command Prompt window.
-
Enter the following command to connect to a PostgreSQL database.
psql -hDatabaseEndpoint-p 5432 "dbname=DatabaseNameuser=UserNamesslrootcert=/path/to/certificate/rds-combined-ca-bundle.pemsslmode=verify-full"In the command, replace:
-
DatabaseEndpointwith the endpoint of your database. -
DatabaseNamewith the name of the database you want to connect to. -
UserNamewith the user name of your database. -
/path/to/certificate/rds-combined-ca-bundle.pemwith the local path where you downloaded and saved the certificate for your database.
Example:
psql -hls-8e81e07f8b821917b11e1c6a0e26cb73c203---czowadgeezqi---us-west-2---rds.amazonaws.com.rproxy.govskope.ca-p 5432 "dbname=dbmasteruser=dbmasterusersslrootcert=/home/ec2-user/rds-combined-ca-bundle.pemsslmode=verify-full" -
-
Type the password for the database user you specified in the previous command when prompted, and press Enter.
You should see a result similar to the following example. Your connection is encrypted if you see a value of “SSL connection."