Cannot connect to datasource in AWS Athena

0

I created a data source with correct credentials to be setup for lambda function connector, for example: postgres://jdbc:postgresql://xxx.us-west-2.rds.amazonaws.com:5432/xxx?user=xxx&password=xxx. VPC, Subnets, Security groups are the same my RDS. But on the Amazon Athena > Query editor, when I select the created data source and click the Database dropdown, then I got the below issue:

Failed to invoke lambda function due to com.amazonaws.services.lambda.invoke.LambdaFunctionException: org.postgresql.util.PSQLException: The connection attempt failed.

Do you have any suggestions to fix this? Thanks.

asked a year ago1354 views
2 Answers
1

please check the connectionstring format it seems wrong

JDBC connection string format (Java applications):

jdbc:postgresql://<RDS_ENDPOINT>:<PORT>/<DB_NAME>?user=<USERNAME>&password=<PASSWORD>

Replace <RDS_ENDPOINT>, <PORT>, <DB_NAME>, <USERNAME>, and <PASSWORD> with your specific values.

Example:

jdbc:postgresql://xxx.us-west-2.rds.amazonaws.com:5432/xxx?user=xxx&password=xxx

profile picture
EXPERT
answered a year ago
  • Thanks for your answer. My connection string format with "xxx" is just an example and it follows the format jdbc:postgresql://<RDS_ENDPOINT>:<PORT>/<DB_NAME>?user=<USERNAME>&password=<PASSWORD> The concern is that this works on my AWS Dev account but when I work on Prod account, it cannot connect to my prod database (I am able to connect to my prod DB with the credential that I used in JDBC connection string). Do you other suggestions on this?

    • Check if the security group attached to your RDS instance allows inbound traffic from the Lambda function's security group or IP range.
    • Verify that the username and password for the RDS instance are correct and have the required permissions to connect from the Lambda function.
    • Check if there are any network ACLs or firewall rules that might be blocking the connection between the Lambda function and the RDS instance.
    • Ensure that the RDS instance is accessible from the internet or that the VPC endpoint is configured correctly if you are using an interface VPC endpoint.
0

Please make sure that the security group you have selected while creating the lambda function (SecurityGroupIds) has an inbound rule allowing connection from your database on port 5432.

profile pictureAWS
Anand
answered a year ago
  • Yes, I created an inbound rule but I don't know what IP if choose "Custom" source (if select "Anywhere-IPv4" and 0.0.0.0/0, then it works). Could you tell me how to config inbound rule so only lambda can connect to RDS?

  • A good practice is to select the respective 'security group id' instead of IP addresses. With 'Custom' as source, you should be able to select security groups. In the Inbound rules of security groups of lambda and RDS, make sure that you only select the security groups of each other to allow access only between them. Hope this helps

  • Thank you for your helps. I added subnet's IPs to security group, it works now.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions