2

I have an AWS Lambda function for an API. I have a test function inside of the API that returns a "Success" string so I know that I can hit the API from my machine (Postman).

The Lambda API is inside of my VPC. I have public and private subnets. The API is living in the public subnets. I also have a RDS database that's living in the private subnets. I can connect to the database through a Bastion host so I know the database is connected and working.

When I try an API call that connects to the database, I can see an error in CloudWatch that says:

[Error] Amazon.Lambda.AspNetCoreServer.APIGatewayProxyFunction: Unknown error responding to request: MySqlException: MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> System.InvalidOperationException: Sequence contains more than one matching element

There's a lot of references to that error message that talks about the Linq SingleOrDefault() method, but I don't have any references to that method.

I think that error has something to do with the security groups. I have an RDS security group that has an inbound rule on port 3306 from my internal VPC ip addresses.

The security group for my Lambda function should be ok since I can successfully hit the test route.

Finally, I tried connecting to the database through the API in debug on my machine and I get an error "The requested name is valid, but no data of the requested type was found"

Does anyone have any other ideas or places to look?

2 Answers2

0

Can you check your this setting is enable or not for RDS Security group ?

Inbound RDS Security Group

Outbound RDS Security Group

Disclaimer : Allowing inbound traffic on DB from internet is not recommended and should always be avoided

Avinash Dalvi
  • 8,551
  • 7
  • 27
  • 53
0

My RDS database (that I was trying to connect to and read from using AWS Lambda) was also a MySQL database.

When I tested the Lambda function I was getting 'Unable to connect to any of the specified MySQL hosts' (after waiting -- like it was timing-out).

I reviewed the answer from @aviboy2006, which helped me. I tried all the Security Group rules shown in that answer. I found I was able to successfully connect-to and read from the RDS MySQL database when I defined both an Inbound and Outbound rule for the associated VPC Security Group as

Type: MYSQL/Aurora
Protocol: TCP
Port Range: 3306
Source: Custom: 0.0.0.0/0

enter image description here

StackOverflowUser
  • 945
  • 12
  • 10