Configuration
Cloud Functions can be used to integrate with external services. Most API's require credentials that need to be stored. These should not be hard-coded into your code. Cloud Functions can be configured using YAML.
The configuration can be created locally by setting the configuration in the context_values.yaml
file in the root of your workspace. There are no requirements on the format, other than that the root should be an object (i.e. not a string, array or number). This is the preferred place to put your credentials for development.
The context_values.yaml
file is not used if your Cloud Function runs in IXON Cloud. In IXON Cloud you can set the configuration in Admin. The configuration set in Admin is stored encrypted.
Make sure you use the same schema locally and in the cloud, or your Cloud Function may not work correctly.
Using the config
The configuration is made available via the FunctionContext
. Note that numbers (integers and floats) are parsed as strings. The configuration is accessible via the config
field in the context.
apiApplication: pubidxxxxxxx
externalService:
hostname: api.reallyusefulservice.com
username: user
password: pass
from ixoncdkingress.function.context import FunctionContext
@FunctionContext.expose
def hello_world(context: FunctionContext, **kwargs: Dict[str, str]):
# prints "pubidxxxxxxx"
print(context.config['apiApplication'])
# nested objects in the config are
# in nested dicts in the function:
# context.config['externalService']['username']
Default configuration
In order to help administrators with configuring your Cloud Function, you can provide a default configuration that will be copied upon install or share. A default configuration can be set in the Cloud Function details in the Studio.
You can use any valid YAML, so you are encouraged to make use of comments to clarify the various configuration options of your Cloud Function.
Keep your secrets safe!
The default configuration is not encrypted and is shared with all users of your Cloud Function. It should therefore not contain secrets!
Updated about 1 month ago