I am trying to connect to an RDS from a Serverless function.
The setup works on my local, with a database running on my machine, and executing the serverless function on my local. The issue is when I deploy the serverless function into AWS, then function can't connect to the database. The logs show the following error
2022-07-08T15:17:05.181Z a9d9a81b-dec6-43f8-83db-a3a36cf433d1 ERROR PrismaClientInitializationError:
Invalid `s.manufacturers.findMany()` invocation in
/var/task/src/manufacturers/get/index.js:1:211
→ 1 (()=>
Can't reach database server at `xxxx.yyyy.us-east-1.rds.amazonaws.com`:`5432`
Please make sure your database server is running at `xxxx.yyyy.us-east-1.rds.amazonaws.com`:`5432`.
at RequestHandler.request (/var/task/node_modules/@prisma/client/runtime/index.js:49028:15)
at async PrismaClient._request (/var/task/node_modules/@prisma/client/runtime/index.js:49919:18)
at async r.getManufacturersPrisma (/var/task/src/manufacturers/get/index.js:1:189)
at async e.handler (/var/task/src/manufacturers/get/index.js:1:581) {
clientVersion: '3.15.2',
errorCode: undefined
}
I have a VPC with 4 subnets, 2 publics, and 2 privates. The database is on one of the private subnets. I am able to connect to the database from my local, through an EC2 running on the public network, via ssh.
The database and the lambda are in the same VPC, and the Serverless function is running on one of the subnets that the RDS has listed. I am not sure which I step I missed in this setup or how can I debug this.
CodePudding user response:
Just in case it is helpful for someone else
I need to edit the inbound rules for the rds security group and allow the lambdas CIDR block to access the database