The Node.js AWS Lambda Generator Guide
Overview
The Node.js AWS Lambda generator lets you set up and deploy an OpenLegacy service running on Node.js in the AWS Lambda serverless environment. The service enables you to expose APIs to several remote data source types, including Oracle DB, SQL Server DB, CICS-COBOL, VSAM-CICS, IMS-PL1, IMS-COBOL, Sybase DB, and more.
At the end of this unit, you will learn to:
- Generate a Node.js AWS Lambda service.
- Build the service as a Node.js AWS project.
- Test the Node.js AWS project locally.
- Deploy the project to AWS.
Prerequisites
Satisfy the following prerequisites:
- Install NPM v6 or later.
- Install Node.js v12 or later,
- Install the AWS Command Line Interface and configure it with your login credentials and AWS settings.
- Create a writable Amazon S3 Bucket.
- Have at your disposal the credentials of an OpenLegacy Jfrog Artifactory user with permissions to the ol-npm-native repositories.
Step 1: Generate a Node.js AWS Lambda service
First, generate a service using an OL Hub project and the Node.js AWS Lambda generator; see the ol generate command reference topic to learn more about service generation.
Currently (Jan 2022), the Node.js AWS service supports modules with the following connectors:
- oracle-db
- sqlserver-db
- mf-cics-cobol
- vsam-cics
- mf-ims-pl1
- mf-ims-cobol
- sybase-db
- ibm-mq-cobol
- ibm-mq-pcml
- as400-cobol
- as400-pcml
Only one method per service can be deployed to AWS Lambda. If the project contract contains more than one method only the first one will be deployed.
> ol generate --project "your_project_name" --generator aws-nodejs-lambda
$ ol generate --project "your_project_name" --generator aws-nodejs-lambda
The generated service folder is created. The folder is carrying the project name.
Step 2: Build the Node.js AWS service
Before you can deploy the service you generated in step 1, you have to build from the generated service a Node.js application. Then, in Step 4, you'll deploy the application to AWS Lambda.
Each deployable application consists of a native core library and a wrapper. The core library is dedicated to a specific remote data source, and the wrapper integrates the core library to the Node.js environment.
During the build, NPM pulls the Node.js core-native library wrapper from the OpenLegacy artifactory.
After you have completed the NPM configuration, install the ol-npm-native package using the npm install command:
> npm install
$ npm install
The node_modules directory containing the core-native library wrappers is created in your service directory.
Step 3: Test the Node.js AWS Project
After successfully building the Node.js application, you can test how it handles requests before deploying it to AWS Lambda.
- Copy the contents of the in.json file used to test the asset with the ol test asset command when you created the original module.
- Paste the contents in the test-input.json stored inside the service root directory.
- Execute the npm test command.
> npm test
$ npm test
The test results are printed to the console:
> npm test
> [email protected] test
> node -e "console.log('Test output: ', require('./index').handler(require('./test-input.json')));"
Input:
{
"dfhcommarea": {
"itemNum": 1001
}
}
Output:
{
dfhcommarea: {
itemNum: 1001,
itemRecord: {
itemName: 'Ball Pool',
description: 'Ball Pool - Novelty Toys',
weight: 100
},
shipping: { shippingMethod: 'AIR MAIL', days: 2 }
}
}
Test output: Promise {
'{"dfhcommarea":{"itemNum":1001,"itemRecord":{"itemName":"Ball Pool","description":"Ball Pool - Novelty Toys","weight":100},"shipping":{"shippingMethod":"AIR MAIL","days":2}}}'
}
Step 4: Deploy to AWS
After successfully testing the local Node.js AWS project, you can finally deploy the project to the AWS Lambda platform using the AWS CLI.
Updated 4 months ago