How to connect SageMaker to an RDS proxy database

0

I wanted to know if I can use sagemaker to connect to an existing Rds proxy postgres database please.

On the AWS site, I saw a diagram showing multiple laptops connected to an RDS proxy. Is there a way to get my sagemaker or multiple sagemakers to access the RDS Proxy with an existing postgre database.

Basically, I launched a jupyter notebook instance from sagemaker and tried these python codes but they failed.

Any recommendations on how to connect sagemaker to an RDS proxy database, please.

======================================

import boto3
import psycopg2

# AWS RDS details
region = '       '  # Sydney region perhaps
db_username = 'your_db_username'
db_endpoint = 'your-rds-proxy-endpoint.amazonaws.com'
db_name = 'your_db_name'

# Boto3 RDS client
rds_client = boto3.client('rds', region_name=region)

# Generate IAM authentication token
token = rds_client.generate_db_auth_token(
    DBHostname=db_endpoint,
    Port=5432,
    DBUsername=db_username
)

# Connect to the database
conn = psycopg2.connect(
    host=db_endpoint,
    port=5432,
    user=db_username,
    password=token,
    dbname=db_name,

sslmode='require'

)

print("Connection established")

Steel
asked 12 days ago304 views
2 Answers
0

Hi,

This KB article show how to connect SageMaker to an RDS instance (proxy doesn't change anything: just use address of proxy instead of RDS instance): https://repost.aws/knowledge-center/sagemaker-connect-rds-db-different-vpc

This post shows also how to do from a Jupyter Notebook: https://medium.com/@sjacks/using-rds-on-aws-with-jupyter-notebooks-c2703299fcc8

Here you have a full example with the pgvector extension on Postgresql RDS: https://github.com/aws-samples/rds-postgresql-pgvector/blob/main/rdspg-vector.ipynb

Best,

Didier

profile pictureAWS
EXPERT
answered 12 days ago
profile picture
EXPERT
reviewed 12 days ago
  • Since I am using a token as authentication, I can't seem to get the details of user details or db name. Therefore when the second link that you provided it's still failing.

0

I am still getting an error saying connection to server <myserver>, port 5432 failed, password authentication failed for user " username ".

Any suggestions please.

Steel
answered 12 days ago