3

I'm trying to access AWS QLDB via API gateway and a Lambda expression but can't find any documentation on it, can anyone tell me if this is possible?

The plan is for an open API so that it is language agnostic but all I can find is reference to installing the driver in the client, but as the driver is only really available in Java it's pretty restrictive. Have I missed something or is that the only way at present? Is there a better approach maybe?

Would really appreciate a nudge in the right direction.

10PinT
  • 33
  • 5
  • I'm not particularly familiar with the details of QLDB, but it looks similar to Amazon Redshift -- the API is used for ledger-level operations, while data-related operations are performed through an [SQL client](https://docs.aws.amazon.com/qldb/latest/developerguide/getting-started-driver.html). There are drivers and code samples provided for Node, Java and Python. – John Rotenstein Feb 06 '20 at 21:12
  • 1
    Both the Node and Python drivers are classed as preview so I wasn't keen on using them, and while I don't know Java at all it looks like I need to install a library and compile which seems infeasible to do in Lambda, but maybe I don't understand Java in Lambda – 10PinT Feb 06 '20 at 22:01
  • Don't be scared of the "Preview" tag. QLDB is quite new, and "Preview" means that they reserve the right to change the API based on feedback from customers. If you prefer Node or Python, I would recommend using the preview drivers. – John Rotenstein Feb 06 '20 at 22:04

2 Answers2

5

I've got a simple demo app here - https://github.com/mlewis7127/qldb-simple-demo

This uses the Serverless Framework and you can run sls deploy to deploy the stack which consists of:

  • QLDB Ledger with a Vehicle table and index
  • POST API to create a new vehicle record using API Gateway and Lambda
  • GET API to retrieve the vehicle record using API Gateway and Lambda

There's lots of enhancements I need to make to it, but it should get you up and running. I am using Nodejs for this, but plan on creating a Java version with Lambda for comparison

Matt Lewis
  • 91
  • 2
  • This will definately help, thankyou. I need to upskill my Python but think I get the gist of it now – 10PinT Feb 18 '20 at 17:50
1

For anyone wanting to get started with a super-simple QLDB & Lambda "Hello World!" here's a demo I put together.

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

Here's the Lambda function:

var qldb = require('amazon-qldb-driver-nodejs');
var qldbRecord;
const driver = new qldb.QldbDriver("helloworld");

exports.handler = async (event) => {

    await driver.executeLambda(async (txn) => {

        qldbRecord = (await txn.execute("SELECT * FROM greeting WHERE exclamation = 'Hello'")).getResultList();
        
    });

    const response = {
        statusCode: 200,
        body: qldbRecord.toString(),
    };
    return response;
};

QLDB driver is here: https://github.com/awslabs/amazon-qldb-driver-nodejs

How to add the driver to Lambda is here: https://www.youtube.com/watch?v=RnFowJ130pc

John Mayo-Smith
  • 139
  • 1
  • 7