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.

preguntada hace un año1412 visualizaciones
2 Respuestas
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
EXPERTO
respondido hace un año
  • 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
respondido hace un año
  • 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.

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas