Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access to RDS from Amazon Lambda, same VPC and correct role permissions

i can't successfully connect to RDS from Amazon Lambda in production. For Amazon Lambda i'm using Serverless framework, executing sls offline i can connect with RDS from localhost, but in production Amazon Lambda doesn't.

Both are in same VPC, in same security group, that has all traffic inbound access, and a rule that is pointing to Vpc's CIDR.

I have these permissions attached: AmazonRDSFullAccess, AWSLambdaFullAccess, AmazonVPCFullAccess, AWSLambdaExecute and AWSLambdaVPCAccessExecutionRole.

Thank's for help.

like image 671
fabian818 Avatar asked Sep 01 '17 00:09

fabian818


People also ask

Can Lambda access RDS in VPC?

A Lambda function that is outside of a VPC cannot access an RDS instance that is inside a VPC. For information on how to configure a Lambda function's network settings, see Configuring a Lambda function to access resources in a VPC.

Can Lambda access resources in VPC?

Lambda functions can't connect directly to a VPC with dedicated instance tenancy. To connect to resources in a dedicated VPC, peer it to a second VPC with default tenancy .


1 Answers

I had this issue and the following is a summary of the steps I took to resolve:

  1. In lambda network section select the VPC and all subnets. Set the security group to the security group the RDS was created with / set to.
  2. Edit said security group inbound policies and set a policy with RDS port/access settings and set the source equal to its own Group Id. It is not sufficient that they are in the same group, if it doesn't accept connections from it's own group.
  3. Ensure the lambda function execution role has AWSLambdaVPCAccessExecutionRole and AWSLambdaBasicExecutionRole policies attached.

Good luck.

like image 182
edencorbin Avatar answered Oct 05 '22 22:10

edencorbin