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

5:51
已提問 3 年前檢視次數 521 次
3 個答案
0

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

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

5:51
已回答 3 年前
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

5:51
已回答 3 年前
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

已回答 3 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南