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.

질문됨 일 년 전1412회 조회
2개 답변
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
전문가
답변함 일 년 전
  • 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
답변함 일 년 전
  • 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.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠