Reputation: 21
I have a python 3.6 script that needs to get executed on AWS Lambda. The script needs to establish a connection to RedShift - being done through psycopg2.
The deployment package has been created with the appropriate compatible psycopg2 version.
When establishing a connection - i.e., conn = psycopg2.connect(...) -, the script times out at thresholds from ranges as small as 5 seconds to ranges as large as 5 minutes (when executing the script locally, it takes less than 5 seconds).
If I remove the connection statement (i.e., conn = psycopg2.connect(...)), the script does not time out - the success prompt gets produced instantaneously.
If anyone experienced a similar issue, your input would be very much appreciated.
The wheels keep spinning
Upvotes: 2
Views: 4595
Reputation: 430
I also faced the same issue while connecting to Redshift using psycopg2 using my lambda function.
Solution -
After this you can try testing your lambda function your psycopg2.connect(...) will create successful connection using your lambda function.
Cheers!
Upvotes: 0
Reputation: 471
If your script hangs on the psycopg2.connect(...) call, than the security group associated with your lambda function, is not allowed access to the Postgres database instance.
Check the security group associated with the database it should have an Ingress which grants access to the security group associated with your lambda.
"DatabaseSecurityGroupIngress": [
{
"IpProtocol": "tcp",
"FromPort": "5432",
"ToPort": "5432",
"SourceSecurityGroupId": {
"Ref": "LambdaSecurityGroup"
}
]
Upvotes: 2