How do I assign a static IP address to a Lambda function?

2 minute read
1

I want to assign a static IP address to an AWS Lambda function.

Resolution

Follow these steps to assign a static IP address to a Lambda function.

Attach a Lambda function to an Amazon VPC

Attach a Lambda function to an Amazon Virtual Private Cloud (Amazon VPC) in your AWS account. The Lambda function is assigned an elastic network interface with a private IP address. The Lambda private IP address can't be assumed as the static IP address because it's changed as part of the network interface lifecycle.

For more information, see Giving Lambda functions access to resources in an Amazon VPC.

Note: It's a best practice to place Lambda functions in an Amazon VPC only if the function must access other resources in the Amazon VPC.

Grant internet access to a Lambda function in an Amazon VPC

Internet access from a private subnet requires NAT. To grant internet access to a Lambda function that's connected to an Amazon VPC, route its outbound traffic to a NAT gateway or NAT instance in a public subnet. Make sure that the NAT gateway or NAT instance has a route to an internet gateway.

For more information, see How do I give internet access to a Lambda function that's connected to an Amazon VPC?

Associate the NAT gateway or instance with an Elastic IP address

Associate an Elastic IP address with the public NAT gateway or instance. The NAT gateway or instance replaces the source IP address of the instances with the Elastic IP address. This Elastic IP address can be assumed as the static IP address for the Lambda function.

Note:

  • It's a best practice to create multiple subnets across different Availability Zones. This practice creates redundancy and allows the Lambda service to maintain high availability for your function.
  • Elastic IP addresses can be associated only with a public NAT gateway or instance. They can't be associated with a private NAT gateway or instance.
  • The default quota limit for Elastic IP addresses per public NAT gateway is 2. However, you can request a quota increase up to 8. For more information, see Elastic IP addresses.

Related information

Activate internet access for a VPC using an internet gateway

AWS OFFICIAL
AWS OFFICIALUpdated 11 days ago