I run a service on my EC2 instance and I want to setup an inbound rule that only allows my lambda function to access it. The security group allows me to restrict access by a
You can refer below articles to do the same,
1. https://medium.com/@justanotherspyy/how-to-connect-your-lambda-function-securely-to-your-private-rds-instances-in-your-vpc-29789220a33
2. https://medium.com/orchestrated/steps-to-secure-aws-serverless-lambda-part-1-a6e5d1b05f45
The summary would be,
1. Create a role for Lambda using below two policies,
AWSLambdaBasicExecutionRole — provides CloudWatch logging.
AWSLambdaENIManagementAccess — provides ENI description, creation, and deletion.
2. Put lambda in the same VPC of EC2 and create a security group for the lambda function.
3. Put this security group in EC2's security group's inbound rules.