By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Lambda connect to Aurora serverless MYSQL

0

I place lambda in app private subnet and place aurora serverless compatible Mysql in db private subnet. Both are in the same VPC. I use ec2 to test connect to db and it works just fine. I use default security group which inbound and outbound allow all traffic for testing purpose. But lambda cannot connect to db and got timeout error, even though there is only 2 rows in table. I tried delete vpc and test again it gave me this error: HttpEndpointNotEnabledException. I use boto3 execute_statement. From chatgpt, execute_statement use data api , which is not support for mysql, so I though this is the problem. I switch back to use pymysql, and it work. Is my assumption for the problem is right ?

1 Answer
1
Accepted Answer

Hello.

The RDS data api must be able to access the RDS service endpoints.
Therefore, it is thought that the timeout error is occurring because Lambda connected to the VPC cannot access the RDS service endpoint.
Therefore, try setting a route for NAT Gateway in the route table of the subnet to which Lambda is connected, or create a VPC endpoint for RDS.
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html#data-api.vpc-endpoint

By the way, Aurora Serverlessv2 MySQL allows you to use the Data API.
I think you can connect if the region you are using and the version of Aurora MySQL support the Data API.
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Concepts.Aurora_Fea_Regions_DB-eng.Feature.Data_API.html#Concepts.Aurora_Fea_Regions_DB-eng.Feature.Data_API.ams

Also, check if the Data API is enabled.
https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html#data-api.enabling

profile picture
EXPERT
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • Thanks for your responding. I checked the document and found out that when choosing engine version, I chose the default which is 3.05, my region only support data-api if engine version is 3.07 or higher.

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