LearnerGuy
LearnerGuy

Reputation: 23

How to connect AWS Lambda and RDS in VPC

How can I create this scenario:

- A private subnet-1
- Lambda in subnet-1
- RDS in subnet-1(same subnet with Lambda)
- Both inside the same VPC. 

is the above feasible and is it a good architecture ?

I have tried implementing it only issue is, it's timing out. But, when the Lambda is out of the subnet-1 it's working fine.

My understanding is since both RDS and Lambda are in the same subnet they should easily communicate.

Upvotes: 1

Views: 1171

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269284

It is perfectly okay to have Amazon RDS and the AWS Lambda function connected to the same private subnet.

Some things to note:

  • If the Lambda function also requires access to the Internet (eg to make calls to Amazon S3), then the VPC will also require a NAT Gateway in a public subnet.
  • The Lambda function should refer to the RDS instance by DNS Name. This should resolve to a private IP address local to the VPC.
  • The Lambda function should be assigned a Security Group (eg Lambda-SG)
  • The security group associated with the RDS instance (RDS-SG) should permit inbound access on the appropriate port (eg 3306 for MySQL) from Lambda-SG.

That is, RDS-SG should permit inbound connections from Lambda-SG.

Upvotes: 2

Related Questions