To pack and deploy the sample, you need Node.js installed on your computer.
You can download it for free from here.
To download the code, make sure you have GIT installed and execute the following command from our command line:
git clone https://bitbucket.org/softimize/notifications-handler-lambda-seed.git
To download dependencies, execute the following command line:
The following boilerplate functions should be executed before the code can be executed:
(You may change them as required)
- extractDataFromEvent - Extracts the data and metadata from the event.
- getTraceId - Get a trace ID from the event (or fallback to a trace ID from a BioT service). The trace ID is used for better logging traceability.
- configureLogger - Create new logs format (including a traceId).
- authenticate - Authenticate the token sent by the notification service.
- login - Login to BioT (using a service user) and get a token.
- callToAPIExample - An example of calling a BioT service.
- response - Send response (see errorResponseCreator for error responses).
A helper function that obtains the raw JSON data from the event.
The trace ID is a unique ID string that will be set in the header of each API call and saved to the log. Using this unique ID will allow us to trace the whole flow of the call, in case of a problem, beginning with the plugin and going through all the API calls that the plugin made, and any internal API calls made by the platform until the plugin response.
This function prepares the log structure for a well-structured log that will enable easy searching when needed.
This function validates the JWT token received from BioT to ensure the call originated from there and not from any unauthorized origin.
Before making an API call to BioT the plugin needs to obtain a new JWT token using the service user credentials.
This is an example stub code to be replaced with your business logic.
The response depends on the plugin and should be updated according to your business logic.
You may want to zip the source code before deploying it by executing the following command:
npm run zip
To deploy the code, refer to Custom Plugin Deployment.
The following environment variables need to be set before the plugin can be executed:
Name of this Plugin, used for logging purposes.
The base API URL of your BioT account.
Set as ACTION_NOTIFICATION
The public key of BioT, used to ensure the call originated from BioT. The key can be obtained by making a request to:
The service user ID.
The service user secret key.
To set these environment variables, login to the AWS console and go to the Lambda service.
From the list, select your Lambda function and click on "Configuration", then "Environment Variables" and finally "Edit".
In the Edit Environment Variables box that appears, enter the environment variables as keys and values. To add more than one environment variable, click Add environment variable. When finished, click Save.
Updated 10 days ago