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

走远了吗. 提交于 2020-03-22 03:26:35

问题


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?


回答1:


I agree with John Rotenstein that connecting your local machine to a Lambda running on AWS is probably a bad idea.

If your intention is to develop or test locally, I recommend the serverless framework, and the serverless-offline plugin. It will allow you to simulate Lambda locally, and you can pass database config values through as environment variables.

See: Running AWS Lambda and API Gateway locally: serverless-offline




回答2:


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.


来源:https://stackoverflow.com/questions/49877635/is-it-possible-to-connect-to-database-hosted-in-local-machine-through-aws-lambda

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!