I'm not very good with networking, but here is my issue: I need to connect to MySQL server from AWS lambda function, that is behind firewall, and to 'white' my AWS lambda i need to know what IP it uses.
As i understand, it varies depending on VPC subnet. Is it right, that if my VPC subnet CIDR is 172.31.16.0/20, IP may vary from 172.31.16.0 to 172.31.16.254 ?
The IP addresses in the 172.31. 16.0/20 are private, non-routable addresses. Unless your MySQL server and firewall are in the same VPC, your Lambda will only be able to connect through NAT and will use the elastic IP attached to your NAT Gateway. That's the only IP address you need to whitelist.
The pattern's approach helps you create an AWS Lambda function that uses an Elastic IP address as the outbound IP address. By following the steps in this pattern, you can create a Lambda function and a virtual private cloud (VPC) that routes outbound traffic through an internet gateway with a static IP address.
Since we are not using Elastic IP for our NAT instance, it will get a new public IP, every time it's started.
You have an MySQL instance that is not on AWS infrastructure. You want to limit access to the the MySQL instance by the IP of the Lambda function to your on-premise instance. You can only use a local firewall to secure the instance.
Since your use case requires internet access from Lambda to your MySQL instance on the public internet, you will need to configure a NAT gateway for your Lambda function to access the internet.:
if your Lambda function requires Internet access..., you can configure a NAT instance inside your VPC or you can use the Amazon VPC NAT gateway. For more information, see NAT Gateways in the Amazon VPC User Guide.
Using a NAT Gateway configuration allows your Lambda requests to come from the fixed IP of the NAT Gateway. If you assign and Elastic IP Number to the NAT Gateway here, you can then specify that IP/port combination on your firewall to secure access to your on-premise SQL instance.
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