Entrypoints - NodeJS

Entrypoints enable injecting business logic into the flow engine via code.

This can be used for cross-cutting concerns like logging, introducing complex mapping logic that cannot be done using the Flow UI in the Hub, or any other use case that requirescustom code.

How to Generate

ol list generators # lists all available generators. Use it to ensure that you have aws-nodejs-lambda generator or its name hasn't been changed ol list projects # lists all your available projects in the Hub ol generate --project ${your_project_name} --generator aws-nodejs-lambda # generates a new Node.js project using AWS Node.js lambda generator cd ./${your_project_name}

The generated project will have the following structure:

./index.js # the main handler ./scripts # directory with provided scripts ./scripts/undeploy.sh # deletes Lambda function and its role ./scripts/trust-policy.json # a .json file that configures a new role for the AWS Lamda function. Used in the deploy script ./scripts/deploy.sh # creates a new role, new AWS Lambda function, packs all code to the .zip file and deploys to the AWS ./ol # contains Hub project metadata ./ol/metadata.opz # Hub project metadata packed as a .zip file ./ol/.ol-connections.json ./properties.json # contains configuration properties for getting OpenLegacy project metadata ./package.json # describes Node.js project build dependencies ./test-input.json # file that used for specifying a test input payload and testing a Lambda function Node.js handler locally using npm test command

How To Test Locally

After successfully building a project locally with npm install, the AWS Lambda handler can be tested locally using npm test command. The test request, i.e., input, must be provided in the test-input.json file. After executing npm test, the content of this file will be sent as the event to the AWS Lambda handler and the result of its execution will be printed to the console.

How To Add and Test an Entrypoint

After successfully executing npm install and npm test, add your entrypoint logic into index.js, for example:

Entrypoint Interface:

wrapper.addEntrypoint( '{type}', // type is the entrypoint type can be FLOW or STEP '{name}', // name is the relvent flow/step name in the contract (ctxStr) => { // The Before Entry point - this action will happen before the operation will be executed in the flow engine }, (ctxStr) => { // The After Entry point - this action will happen after the operation will be executed in the flow engine } )

Flow Entrypoint:

 

Step Entrypoint:

We can extract the step name from inspecting it in the browser (inspect the project canvas in the browser → Network → Select the method by it’s ID → Preview → flow → steps)

 

In this case, we used the mf-cics-cobol module, and tested the Get Account asset with the following request in test-input.json:

We can see that the original request actiAccountId was 22277234914, after inserting the entrypoint logic, we will be able to change the request actiAccountId value to 75906882668.

After editing the index.js file, execute npm test again to inspect the changes implemented by adding the entrypoint.

To deploy, please refer to: Node.js AWS Lambda low-code generator