Skip to main content
All CollectionsUser Guides
UbiFunctions: Using Global Properties
UbiFunctions: Using Global Properties

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

Sergio M avatar
Written by Sergio M
Updated over 6 months 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 the “my profile” section of your Ubidots account.

  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. Currently, only JSON is 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.

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?