Skip to main content

    Build custom functions with Code

    Course overview
    Lesson
    3 min read

    Navigate the Code editor

    Learn how to use the different parts of the Code editor to build and deploy custom Code functions.

    Identify different parts of the Code editor

    There are a few different features within the Code editor that help you have complete control over your custom functions. Click through the following tabs to learn more about each feature.

    Code editor

    The Code editor is where you will write all of the code that makes up your function.

    You can write in either Python or JavaScript, which you will select when you create your function.

    Modules

    This screen lists all modules that have been added. To add a new module, click Add new module.

    Once a module has been added, you can import and use it in your function. Modules need to be added separately for each function.

    Environment variables

    Environment variables exist in the scope of your function. You can set them here, then access them in your code.

    In Python, access environment variables using os.getenv("NAME"), where NAME is the name of the environment variable.

    In JavaScript, use process.env.NAME.

    Save sensitive data, like private API keys, as environment variables to maintain data security.

    Test output

    You can test your function from this tab by clickingRun test and selecting one of the 10 most recent events from the last 30 days to test with. If there have been no triggering events in the last 30 days, no events will be available for testing.

    The output of your test will be shown here. If the function fails, a traceback will show where the error occurred.

    Logs

    Once the function has been set live, the Logs tab will show all of the times the function has been triggered. The overview will show whether each invocation of the function was successful or unsuccessful.

    You can click on each log to view details about the function being triggered, including any console output, information about the triggering event, and how long the function took to run.

    Notes on syntax

    Any blank Code functions you create will be pre-populated with the required event handler.

    In a Python function, the event handler is:

    python
    def handler(event, context):

    In JavaScript, the event handler is:

    javascript
    export default async (event, context) => {}

    Include an event handler in your function to make sure the function runs in response to the triggering event.

    Navigate the Code editor