Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws lambda access ec2

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?

like image 643
Anh Tuan Nguyen Avatar asked Oct 23 '17 10:10

Anh Tuan Nguyen


People also ask

Can Lambda Access EC2 instance?

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.

Can Lambda access private subnet?

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.

What AWS resources can Lambda access?

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).

Can Lambda function access with dedicated tenancy VPC?

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.


1 Answers

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).

like image 50
Sergey Kovalev Avatar answered Oct 27 '22 13:10

Sergey Kovalev