I am trying to connect to a Redshift serverless db I created on AWS using local python code. The db has data, and I can query it using query editor v2, however I am having issues connecting to it in python using redshift_connector, which based on documentation should work with serverless.
Here is my code:
conn = redshift_connector.connect(
host='hostid',
database='dev',
port=5439,
user='my user',
password='my pw'
)
Here is my error:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
I am filling in the host using the endpoint field, removing the :5439/dev at the end, so it is of the format <name>.111111111111.<aws-region>.redshift-serverless.amazonaws.com Redshift host name location
I get a different error if I modify this, so I believe it is correct, and the database/port appear to be correct based on the image as well.
In my searching to get at this problem I found out I should set the namespace to be publicly accessible, which I did, so that shouldn't be a problem: Redshift instance is publicly accessible
The issue persists. My best guess on what is going on is that either:
- I need to toggle some other security setting to allow python to hit the db. What other options do I need to set?
- I don't have the right user/pw credentials. I am unsure of where to find the username and password of the entity that is accessing my redshift db. Only thing I found online is this: https://docs.dataform.co/warehouses/redshift, but that is specific to a redshift cluster, not serverless. I have tried username/pw combinations of my AWS accounts, but none seem to work, and I have also tried using my AWS access keys (which I have used successful in python to move data to/from S3, so I know those work). Where can I find the username/pw of the account that is accessing the data in query editor v2?
conn = redshift_connector.connect(
host='hostid',
database='dev',
port=5439,
access_key_id=AWS_ACCESS_KEY_ID,
secret_access_key=AWS_SECRET_ACCESS_KEY
)
You need to check that port
5439
is open in the security group.Also check that all the selected VPC subnets have a route to an Internet Gateway defined in their route table(s).