I have a python script running on AWS Lambda that tries to connect to a MariaDB I set up on an EC2 Instance.
The script can't execute because the security group of my EC2 instance only allows certain IPs. How can I allow Lambda functions to access?
From AWS Lambda, SSH into your EC2 instances and run commands. AWS Lambda lets you run arbitrary code without worrying about provisioning servers. I recently worked on a project where a Lambda function SSHed into an EC2 instance and ran some commands. This is a very powerful way to control access to your EC2 instances.
You can configure a Lambda function to connect to private subnets in a virtual private cloud (VPC) in your AWS account. Use Amazon Virtual Private Cloud (Amazon VPC) to create a private network for resources such as databases, cache instances, or internal services.
Your Lambda functions can now access Amazon RDS databases, Amazon Redshift data warehouses, Amazon ElasticCache nodes, and other endpoints that are accessible only from within a particular VPC (e.g., web service running on EC2).
Lambda doesn't support running functions in dedicated tenancy VPCs. To connect a Lambda function to a dedicated VPC, first peer the dedicated VPC to a default tenancy VPC that contains the function. The solution requires using an Amazon Elastic Compute Cloud (Amazon EC2) Dedicated Instance.
The recommended way is to place your Lambda inside VPC. This will allow you to choose a subnet and a security group for your Lambda. So all you need to do after that is to modify your EC2 security group to allow connections either from the Lambda subnet (not so good) or from the Lambda security group (much better).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With