Reputation: 195
I'm trying to connect to my Redshift
database from my AWS Lambda
function:
con = psycopg2.connect(
dbname="my_dbname",
host="my_url",
port= 5439,
user="username",
password="my_password")
cur = con.cursor()
But I can't access my database, my function raises the following error:
OperationalError: could not connect to server: Connection timed out
Is the server running on host "my_url" (54.217.83.88) and accepting
TCP/IP connections on port 5439?
Can i get some help with this please ? (and if possible I'd like to have a very detailed answer, because I'm new to AWS )
PS: I know that I have to configure the VPC, but I don't know what to do exactly
Thanks you in advance
Upvotes: 4
Views: 15098
Reputation: 270104
Your goal is to have the AWS Lambda function communicate with the Amazon Redshift cluster within the same VPC, via private IP address. This keeps the traffic within the VPC.
See: Configuring a Lambda Function to Access Resources in an Amazon VPC
Either connect to the Private IP address of the cluster or (preferably) follow the directions on Managing Clusters in an Amazon Virtual Private Cloud (VPC) to enable DNS Hostnames
and DNS Resolution
on the VPC so that the host name will automatically resolve to the Private IP address.
The Security Group associated with the Amazon Redshift cluster will need to permit inbound traffic on port 5439 from the CIDR range of the the VPC (or as appropriate).
See: Amazon Redshift Cluster Security Groups
Upvotes: 6