Skip to main content

UbiFunctions: Using Global Properties

Learn how to create global properties that allow you to speed UbiFunctions development.

Written by Sergio M
Updated over 2 weeks ago

Looking to facilitate UbiFunctions development, Ubidots has introduced Global Properties, a tool that allows you to easily store global variables to speed development and keep resources organized. With Global Properties, easily store and retrieve:

  • Constants.

  • Look-up tables, using JSON objects.

  • Credentials shared across functions.

Requirements

1. Creating a global property

To create a global property, follow these steps:

  1. Go to Dev Center ⟶ Lexicon.

  2. On the left-side panel, go to the “global properties” module.

  3. Click on the “+” button located at the upper right corner of the screen.

Once the creation menu opens up, fill in the following fields:

  • Name: Give your property any name you find suitable.

  • Label: By default, the label is the same as the name you chose, but you can change it to be different. This label will later be used to invoke the global property.

  • Description: Optionally, give the property a description so it can be easily distinguished from others.

  • Format: Choose the property’s format. "JSON" and "text" are available.

  • Value: Click on “add value” and, in the code editor, enter the JSON containing the credential that you want to turn into a global property. You can enter any value here.

Example:

{"aws_keys": "<AWS keys go here>"}
  • Scope: Select the environment in which the global property will be available. Currently, only functions can be chosen, but more options will be added in the future.

  • Secret: Use the toggle button to mark the property as Secret. When enabled, the property’s value will be treated as sensitive information and additional restrictions will apply.

Secret properties are invoked exactly the same way as regular global properties when used inside a UbiFunction. There are no changes to how you access them in your code.

However, their values are protected in the following ways:

  • The value is not visible in the properties module. Neither through the interface (by going into the property's configuration) nor through the browser's console.

  • Once created, a Secret property’s value cannot be edited again. If you need to change the value of a Secret global property, you must create a new property with the updated value and assign it to your function.

Important note: Once a Secret global property is added as an environment variable to a function, its value is available at runtime just like any other property. If your function prints or logs the variable (for example, using print() or console.log()), the value will appear in the function’s output logs.

2. Using global properties

Invoking one of your global properties requires these simple steps:

  • Click on the “devices” drop-down menu and head to “functions”.

  • In your function's settings, click on the environment variables' drop-down menu, select the global properties you want to become available in that particular function, and click on the "update" button.

  • Configure the rest of your function as usual.

  • Somewhere in your code, invoke the global property using the label you assigned to it during its creation. Depending on whether you’re using Python or Node, this process varies:

Python:

import os

def main(args):
aws = os.environ.get('aws_keys')
print(aws)
return {}

Note: Python requires you to import the “os” module.

Node.js:

async function main(args) {
let env = process.env.aws_keys;
console.log(env)
return {}
}

To finish the process, just click on the “save & deploy” button to launch your function. Some runtimes take longer to process, so be patient if your function isn't going live in about 30 seconds.

Did this answer your question?