index.js Implementation

The file index.js that is found in the top-level directory of your unique ID is the main entry point of your lambda function. This file should contain the majority of your JavaScript logic.

Mandatory exports

The file must export in CommonJs formatarrow-up-right the function register which registers the execution triggers that the lambda function is listening on.

module.exports.register = function(engine) {
  // register all triggers here
}

Importing dependencies

The file may import additional .js and .json dependencies that must be found in the same directory as the file index.js itself (or under a subdirectory next to it).

Importing must use the CommonJsarrow-up-right require() syntax.

NPM packages may also be imported, subject to being in the allowed list.

const { ContractAbi } = require("./abi.js");

const Config = require("./config.json");

const BigNumber = require("bignumber.js");

Async await

Asynchronous code can and should use the modern async await syntax directly.

Complete example

The following example monitors an Aavearrow-up-right borrowing position every 10 minutes and if the position is close to liquidation, closes it using a contract that was deployed in advance for this lambda.

Last updated