Function Compute is a fully managed, event-driven compute service that often uses middleware such as databases or message queues for data persistence, data sharing, and message processing.
Database access mechanism
In Function Compute, execution environment instances do not share state. Persist structured data in a database to share state across instances. Access cloud databases through Function Compute to query and insert data.
You can access a database over the public network or through a virtual private cloud (VPC). For better security, access databases through a VPC.
-
Access a database over the public network
For development or debugging, configure a static public IP address for the function and add the IP address to the database whitelist.
-
Access a database through a VPC
In production, place the database in a VPC and configure the function to access VPC resources. Add the vSwitch CIDR block to the database whitelist to enable access to your ApsaraDB instance.
The following figure shows how Function Compute accesses a database through a VPC.
-
A client sends a request to Function Compute.
-
Function Compute uses the configured network settings to access the database in the specified VPC.
Configure the function network in the Function Compute console, or set VPC resources in the Serverless Devs YAML file.
-
After retrieving the data, Function Compute returns the data to the client.