I have my MongoDB living on AWS EC2 and my Lambda function (python code) is trying to access it via IP address 23.23.23.23:27017. At our company we restrict our EC2 instances to our company's IP address by setting up AWS Security Groups on EC2 instance. The problem is without opening up access to port 27017 to all traffic on my EC2 instance security groups my lambda won't be able to access it because we don't know the IP address where the Lambda gets executed on.
Is there a better way to access ports on EC2 instances from AWS services such as Lambda without violating security policies?