Function AI lets you manage configurations and sensitive information across services using variables. You can define project-level shared variables and service-level service variables, and reference them in service configurations. After a service is deployed, the system automatically generates a result variable for it. You can reference this result variable in the configuration of other services to establish dependencies between them.
Variable types
Function AI supports three types of variables: shared variables, service variables, and result variables. The following table compares these types.
|
Variable type |
Shared variable |
Service variable |
Result variable |
|
Scope |
Within the configurations of all services in the current project. |
Within the configuration of the current service. |
Within the configurations of other services in the current project. |
|
Data Type |
String |
String |
String |
|
Reference Syntax |
|
|
|
Notes on referencing variables:
-
After defining a shared variable, you can reference it in the environment variables of any service within the same project by using the syntax
${shared.variable_name}. -
After defining a service variable, you can only reference it in the environment variables of the current service by using the syntax
${self.variable_name}. -
You cannot define custom result variables. When a service is successfully deployed, the system automatically generates its result variable. You can reference this result variable in the environment variables of other services by using the syntax
${output.<service_name>.variable_name}.
Adding, updating, or deleting variables triggers project changes. These changes take effect only after you click Full Deployment.
The environment variables in the configuration of a function service or web service are distinct from the three variable types described above. The value of an environment variable can reference the value of a shared variable, service variable, or result variable. Environment variables are used to retrieve this information in your code, as described in Use environment variables in code.
Result variablesby service type
The following table lists the result variables available for each service type. When referencing a result variable in the environment variables of another service, replace <service_name> with the name of the service. For example, if you create a database service named awesome-keller and deploy it successfully, you can reference its instance endpoint by using the result variable ${output.awesome-keller.host} in the environment variables of a web service in the same project. After referencing this result variable, your web service code can retrieve the database instance endpoint using the method described in Use environment variables in code, allowing it to connect to the database instance.
|
Service type |
Description |
Reference syntax |
|
web service |
Function name |
|
|
Function ARN |
|
|
|
Intranet endpoint for the function's HTTP trigger |
|
|
|
Public endpoint for the function's HTTP trigger |
|
|
|
Custom domain for the function |
|
|
|
async task service |
Function name |
|
|
Function ARN |
|
|
|
function service |
Function name |
|
|
Function ARN |
|
|
|
database service |
Database instance ID |
|
|
Database instance endpoint |
|
|
|
model service |
Model service name |
|
|
Public endpoint |
|
|
|
Intranet endpoint |
|
|
|
workflow service |
Workflow service name |
|
Encrypt variables
Both shared variables and service variables provide an encryption feature, which you can use to manage sensitive information for a project or service, such as database credentials and access tokens. To manage shared variables, go to the project details page and click Project Configuration. On this page, you can view each shared variable's name, value, and the services that reference it. To add, delete, or modify a shared variable, click Edit next to it.
Similarly, to manage service-specific variables, navigate to the service details page and click Service Variables.
If you enable the Encryption switch for a variable, the platform encrypts and manages its value. After you click Save and perform a full deployment, the value appears as ciphertext in the console and deployment logs, never as plaintext.
Once a variable is saved with encryption, you can no longer view its plaintext value. To change the value, click Edit, enter a new value, and click Save. During deployment, Function AI automatically decrypts the value within the deployment pipeline but prevents the plaintext from being exposed in logs or the console. You do not need to perform any extra decryption steps.
Reference variables
-
After defining a shared variable, you can reference it in the environment variables of any service within the same project by using the syntax
${shared.variable_name}. -
After defining a service variable, you can only reference it in the environment variables of the current service by using the syntax
${self.variable_name}. -
You cannot define custom result variables. When a service is successfully deployed, the system automatically generates its result variable. You can reference this result variable in the environment variables of other services by using the syntax
${output.<service_name>.variable_name}.
Variable reference example
For example, a function service's environment variables can reference project-level shared variables, its own service variables, and result variables from other services.
On the Configuration tab of a function service, expand the Environment Variables section. You might see a configuration like this: the value for password is ${shared.password}, which references a project-level shared variable; the value for name is ${self.name}, which references a service variable of the current service; and the value for MYSQL_HOST is ${output.awesome-keller.host}, which references a result variable from the database service named awesome-keller.
Advanced references
Concatenated reference
You can concatenate multiple variables or combine variables with strings. Function AI resolves these concatenated references. For example, you can use the @ character to join two shared variables.
For example, define a shared variable named userName with the value root and another named ipAddr with the value 127.0.01. You can then create a concatenated reference by setting the value of a variable named url to ${shared.userName}@${shared.ipAddr}.
Nested reference
Function AI also supports nested references, where a variable's value references another variable, which in turn contains a reference.
For example, you can define a shared variable prefix with the value fc. Then, define another variable domainName with the value test.${shared.prefix}.com, which references the prefix variable. Finally, you can define a third variable url with the value root@${shared.domainName}, which references the domainName variable, creating multiple levels of nesting.
View the actual value
To apply variable changes, click Save and then Full Deployment. On the shared variables page or the service variables page, you can click
to view the resolved actual value of a referenced variable.
In the nested reference example above, the actual value of the url variable resolves to root@test.fc.com. The system first resolves ${shared.domainName} to test.fc.com by resolving ${shared.prefix} to fc.