Vpc Peering For Lambda
I ve setup vpc peering on my own aws account to test running a lambda from one vpc to query data from a database in another vpc.
Vpc peering for lambda. Why would i place the lambda. When you invoke a lambda function from any invocation source and with any execution model synchronous asynchronous or poll based it occurs through the lambda api. To establish a private connection between your vpc and lambda create an interface vpc endpoint.
Network access control list nacl optional security layer for the vpc acts as a firewall for controlling traffic in and out of subnets. The lambda function and the mongodb ec2 instance reside in two different vpcs so i decided to set up a vpc peering connection to allow communication between the two. Resolution using aws lambda and cloudformation custom resources we can go around this limitation allowing the creation of the vpc peers from within a cloudformation stack.
For security groups choose a security group. Connect your lambda function to your vpc. Today all of the compute infrastructure for lambda runs inside of vpcs owned by the service.
It helps to understand some basics about the way that networking with lambda works. For virtual private cloud vpc choose the default tenancy vpc that you created. Like in the diagram when lambda tries to connect to the database it goes out with the address of database to the route table which directs us to go via the vpc peering to the database.
By default the requester account cannot both request and also approve vpc peering connection requests made to a different aws peer account. For subnets choose two or more subnets in your vpc. You can establish peering relationships between vpcs across different aws regions also called inter region vpc peering.
Interface endpoints are powered by aws privatelink which enables you to privately access lambda apis without an internet gateway nat device vpn connection or aws direct connect connection. This allows vpc resources including ec2 instances amazon rds databases and lambda functions that run in different aws regions to communicate with each other using private ip addresses without requiring gateways vpn connections or separate network appliances.