By using AWS re:Post, you agree to the Terms of Use
/QLDB Query from Lambda Function/

QLDB Query from Lambda Function

0

Sorry for the NewBe question...
My team is evaluating QLDB for a business requirement and needs to run a simple QLDB test in Lambda (node.js 14.x).
Hoping for a super-simple QLDB Lambda 'hello world' js example that executes the following query on the AWS test ledger named 'vehicle-registration':

"SELECT * FROM Person WHERE GovId = 'TOYENC486FH'".

Here's what we have so far:

//var AWS = require("aws-sdk"); //confirming not a dependency to instantiate driver and execute simple QLDB query?
var qldb = require('amazon-qldb-driver-nodejs'); // confirming still a dependency?
var ionjs = require('ion-js'); //confirming still a dependency?
let jsbi = require("jsbi"); //is this a dependency ?

const driver = new qldb.QldbDriver("vehicle-registration");

exports.handler = async (event) => {
// TODO implement
const response = {
statusCode: 200,
body: JSON.stringify('Is there a simple, up-to-date QLDB Lambda example for node.js 14.x?'),
};
return response;
};

AWS, if you're reading this, here are a few things we've observed in the documentation:

  • The second sentence of the QLDB Node.js Tutorial refers to AWS SDK for JavaScript API which is depreciated and comes with a note that says, "Note: You are viewing the documentation for an older major version of the AWS SDK for JavaScript (v2)."

  • The third sentence of the QLDB Node.js Tutorial refers to the QLDB Driver Reference. We managed to import the driver into Lambda but its a time consuming exercise in environment variables, TypeScript, and NPM.

  • IAM role is mentioned zero times in step one and step two

  • Sample code in Step 2 is written in TS even though NodeJS is the runtime for AWS Lambda, and JavaScript is default language.

Edited by: 5:51 on May 14, 2021 3:00 PM

Edited by: 5:51 on May 15, 2021 4:22 AM

Edited by: 5:51 on May 15, 2021 5:16 AM

Edited by: 5:51 on May 15, 2021 9:17 AM

asked a year ago14 views
3 Answers
0

Edited by: 5:51 on May 15, 2021 9:21 AM

Edited by: 5:51 on May 15, 2021 11:13 AM

answered a year ago
0

Anyone looking for a simple Hello World to get started with Lambda & QLDB here's a demo I put together:

https://mayoinmotion.medium.com/hello-world-for-lambda-qldb-e73353459d74

Edited by: 5:51 on May 16, 2021 5:48 AM

answered a year ago
0

Hi John,

Glad that you figured this out! As for your questions,

1/ The second sentence of the QLDB Node.js Tutorial refers to AWS SDK for JavaScript API which is depreciated and comes with a note that says, "Note: You are viewing the documentation for an older major version of the AWS SDK for JavaScript (v2)."

Confirmed the issue. The Node.js sample app tutorial points to the latest version of the AWS SDK for JavaScript v2 API docs (https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/). I can see there is a note banner at the top that says v3 is now available, but our driver and sample app both still use v2.

2/ The third sentence of the QLDB Node.js Tutorial refers to the QLDB Driver Reference. We managed to import the driver into Lambda but its a time consuming exercise in environment variables, TypeScript, and NPM.

I can see that the video you linked uses the original npm init. I would recommend using AWS SAM (https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html) to quickly set up a Node.js 14.x project on AWS, which provides additional support for local debugging and testing, etc. You can run sam init and choose from a number of AWS app templates to get started.

3/ IAM role is mentioned zero times in step one and step two

Confirmed; we'll work on adding additional note about setting up IAM permissions.
At the meantime, setting up IAM permission is part of the steps in Accessing Amazon QLDB: https://docs.aws.amazon.com/qldb/latest/developerguide/accessing.html#setting-up-create-iam-user
We also have a dedicated page with more details on Identity and Access Management for Amazon QLDB if you're interested: https://docs.aws.amazon.com/qldb/latest/developerguide/security-iam.html

4/ Sample code in Step 2 is written in TS even though NodeJS is the runtime for AWS Lambda, and JavaScript is default language.

We have both Javascript and Typescript sample code in: https://docs.aws.amazon.com/qldb/latest/developerguide/driver-quickstart-nodejs.html#driver-quickstart-nodejs.step-2

Thank you for your feedback!

Edited by: aws-yijun on May 18, 2021 10:29 AM

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions