Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to connect to database hosted in local machine through AWS lambda

Tags:

aws-lambda

I launched one RDS instance,s3 and EC2 in AWS and its is triggered properly using lambda. Now I wish to change the change the RDS and EC2 from AWS to local machine. My lambda is triggered from s3.

How do I connect the local database through lambda in AWS?

like image 603
Nimmi Mikku Avatar asked Apr 17 '18 12:04

Nimmi Mikku


1 Answers

It appears that your requirement is:

  • You wish to run an AWS Lambda function
  • Within the function, you wish to connect to a database running on your own computer (outside of AWS)

Firstly, I would not recommend this strategy. To maintain good performance, you should always have an application as close as possible to the database. This means on the same network, in the same location and not going across remote network connections or the Internet.

However, if you wish to do this, then here's some things you would need to do:

  • Your database will need to be accessible on the Internet, so that you can connect to it remotely. To test this, try accessing it from an Amazon EC2 instance.
  • The AWS Lambda function should either be configured without VPC connectivity (which means that it is connected to the Internet) or, if you have configured it for VPC connectivity, it needs to be in a Private Subnet with a NAT Gateway enabling Internet access.
  • (Optional) For added security, you could lock-down your database to only accept connections from a known IP address. To achieve this, you would need to use the VPC + NAT Gateway so that all traffic is coming from the Elastic IP address assigned to the NAT Gateway.
like image 113
John Rotenstein Avatar answered Jan 01 '23 09:01

John Rotenstein