Cvmcosta / ltijs

Turn your application into a fully integratable LTI 1.3 tool provider.
https://cvmcosta.github.io/ltijs/
Apache License 2.0
305 stars 70 forks source link

Serverless support (AWS)? #11

Open nathaniel-holder opened 4 years ago

nathaniel-holder commented 4 years ago

I would love to use this library in an AWS lambda function. That seems like it would require the ability to swap out dependence on an Express server and instead allow the function to be called with HTTP routes that come in through AWS API Gateway. Has anyone considered using ltijs in this way? I'm imagining a server plugin architecture in the same way that you have implemented database plugin support. Thoughts? I'm so happy that this exists and would love to collaborate in making it serverless compatible. ~Nathaniel

Cvmcosta commented 4 years ago

@nathaniel-holder Hello, i'm really glad you are enjoying the project. I'm not too familiar with AWS and the whole serverless idea, but i'd love to learn about it and make it possible with LTIJS.

After a quick google search i found this article and decided to give it a try soon. Could you take a look and tell me if that is what you are looking for?

nathaniel-holder commented 4 years ago

@Cvmcosta Yes, that article looks promising, great find! I have a fair amount of experience with AWS serverless (Lambda & API Gateway) but not with Express, so this is slightly new territory for me. It seems like configuring Express to work with API Gateway could be a configuration option to the LTI constructor? Or maybe you want to package it separately as an Express plugin. AWS is only one serverless cloud provider, so Microsoft Azure or Google Cloud or IBM Cloud folks might also want their own way of integrating LTIJS into their codebase, which might make a plugin model preferrable. In any case, let me know your thoughts and how you'd like to proceed and how I can support this happening!

esellin commented 4 years ago

I am using the serverless framework to deploy my AWS lambas, and it has a plugin to wrap around an Express instance https://github.com/dougmoscrop/serverless-http so if you get hold of the "app" inside your LTI object, it works!

The only trouble is LTI.deploy() telling Express to listen, which we don't want, so it would be nice to have that optional, e.g. passing -1 as a port number?

I have also started work on a AWS DynamoDB database plugin. I'm glad this was abstracted out in your code, well done!

Cvmcosta commented 4 years ago

Hello @esellin! That sounds good, i took a bit of a break from the project this past month and just got back to working on it, your idea is essentially waht i'm planning for this.

Also i'm very happy to hear about the database plugin, i'm working on some changes to the mongo plugin's structure, because when i first wrote it i had a limited understanding of how mongoose and other ODM's ORM's worked, but hopefully nothing that breaks other existing plugins.

I'll will be working on this throughout this week.

Thanks!

Cvmcosta commented 4 years ago

Hello @esellin and @nathaniel-holder. I finally got around to working on this issue. I've added an experimental option to the deploy method that stops the server from listening, like you suggested:

Ltijs v3.1.5

LTI.deploy({serverless: true})

@esellin Can you please try it out sometime? I'd like to make some progress in this issue.

nathaniel-holder commented 4 years ago

@Cvmcosta Thanks, I'll try this out as soon as I can.

@esellin If you can share anything more about how you are managing to use lti.js with AWS Lambda that would be great. Are you also using API Gateway? I am also using DynamoDB - are you able to publish that as a public plugin for lti.js?

raj-durai commented 4 years ago

Hi @esellin @nathaniel-holder , Am also looking for DynamoDB database plugin, I like to try lti.js in AWS Amplify with API Gateway and Lambda. Are there any updates on DynamoDB plugin?

cesarpachon commented 4 years ago

hello, I am also interested in running LTI in AWS Lambda, I did have experience with running hybrid approach: microservices run locally with express, for local dev environment, and the same microservices run in Lambda. What I did was to abstract the microservices signature and create a lightweight adapter for both express and lambda.. example:

//pictures_search.js: microservice to search for pictures
function execute(ctx, params, cb) //this is the common microservice signature. ctx is user security context

this is the express adapter:

function search(request, response, ctx, reply_cb){
  pictures_search.execute(ctx, request.query, reply_cb);
}

and this is the lambda adapter (entry point in AWS Gateway)

exports.search = (event, context, callback) => {
  var ctx = SecurityContext.create(event.context);
  if(!ctx){
    return callback("invalid_auth");
  }
  pictures_search.execute(ctx, event, function(err_code, data){
    callback(util.status2err(err_code, data), data);
  });
};

also I work with mysql so abstraction of persistence layer is a nice idea.

kintz09 commented 3 years ago

Hi everyone! I am also interested in utilizing this library in an AWS Serverless environment. Is there any guidance on how to use this with DynamoDB?

RaphaelWski commented 1 year ago

Hi !

I struggle to make lti.js works in AWS Lambda. Do you have any example about it ?

Thanks

viviancpy commented 17 hours ago

Hello all, I know it is an old post. I came across this and wanted to migrate the Express app to lambda. How do you guys handle the session cookies used in ltijs to become stateless? To my understanding, the wrapper (like serverless-http) only does a wrapper but there could be validation issue inside the ltijs internal if session cookies is not handled properly.

For those who come to this post for Dynamodb, you just need to write a new class to replace the Get, Insert , etc in Database.js class to be Dynamo specific and apply it as plugin when setting lti. It can be done in 1-2 days.