All Products
Search
Document Center

Function Compute:Configure a static public IP address

Last Updated:Mar 26, 2026

By default, the egress IP addresses of Function Compute are dynamic and do not belong to a fixed CIDR block. When Function Compute accesses services such as databases, WeChat Mini Programs, or other third-party services that require whitelisting, you can use the static public IP feature of Function Compute to bind a static public IP address and then add it to the whitelist. This topic describes how to configure a static public IP address for function egress in the Function Compute console.

Usage notes

  • The static public IP address feature uses an internet NAT gateway within a VPC. You create an internet NAT gateway, associate an elastic IP address (EIP) with it, and add an SNAT entry. This configuration allows instances within the VPC to access the internet through the EIP. Receiving services see traffic as originating from the EIP associated with the NAT Gateway.

  • NAT Gateways and EIPs are available only in specific availability zones of a region. If the NAT Gateway and EIP are not in the same availability zone as your Function Compute function, you must configure a vSwitch to enable cross-zone Internet connectivity. For more information, see Availability zones supported by Function Compute.

  • An elastic IP address can be shared among functions in the same region.

  • Before a RAM user can use the static public IP address feature, you must use an Alibaba Cloud account to grant the required permissions. Log on to the Resource Access Management (RAM) console and attach the following policies to the RAM user: AliyunECSFullAccess, AliyunVPCFullAccess, AliyunEIPFullAccess, AliyunRAMFullAccess, and AliyunNATGatewayFullAccess.

Billing

Configuring a static public IP address creates a NAT Gateway and an elastic IP address, which are billable services. For more information, see NAT Gateway Billing and Elastic IP Address Billing.

First-time configuration

Prerequisites

Procedure

  1. Log on to the Function Compute console. In the left-side navigation pane, choose Function Management > Function.

  2. In the top navigation bar, select a region. On the Function page, click the target function.

  3. On the function details page, click the Configuration tab, and then click Modify to the right of Advanced Settings.

  4. In the Advanced Configurations panel, find the Network section. Enable Static Public IP Address and set Allow Default NIC to Access Internet to No.

    Note

    To ensure that your function can access the Internet, first set Allow Default NIC to Access Internet to Yes. After the fixed IP takes effect, set Allow Default NIC to Access Internet to No to smoothly migrate traffic.

  5. Click Deploy. In the Static Public IP Configuration dialog box that appears, carefully read the information, select the confirmation check box, and then click OK.

    The network configuration takes one to two minutes to complete. You can then view the saved network settings. You can also go to the VPC console to view the details of the internet NAT gateway and the associated or automatically created resources.

Verify the result

  1. Log on to the Function Compute console. In the left-side navigation pane, choose Function Management > Function.

  2. In the top navigation bar, select a region. On the Function page, click the target function.

  3. On the function details page, click the Code tab and enter the following code in the code editor.

    The following code is an example in Python.

    # -*- coding: utf-8 -*-
    import logging
    import requests
    
    def handler(event, context):
      logger = logging.getLogger()
      try:
        r = requests.get('https://myip.ipip.net')
        clientIP = r.content.split()[1]
        logger.info('Client IP: ' + clientIP)
      except:
        r = requests.get('http://ipinfo.io')
        clientIP = r.json()['ip']
        logger.info('Client IP: ' + clientIP)
      return clientIP
  4. After you enter the code, click Deploy and then click Test Function.

    After the function executes successfully, check the returned client IP address. It should match the static public IP address that you configured.

Add more static public IP addresses

To add more static public IP addresses, perform the following steps.

  1. On the function details page, click the Configuration tab and click Modify to the right of Advanced Settings. In the Advanced Settings panel, find the Network section. Under the Static Public IP Address setting, click Create new EIP.

    You are redirected to the VPC console.

  2. In the VPC console, manually create an elastic IP address and associate it with the corresponding NAT Gateway. For details, see Apply for an EIP.

    After the EIP is associated, go to the network configuration page of the function to view the saved configuration information.

Related operations

To disable the static public IP address feature or delete a configured IP address, first set Allow Default NIC to Access Internet to Yes. Then, click the configured IP address to go to the VPC console and disassociate the EIP from the NAT Gateway and release the resources.