Vert.x RESTful service on AWS Lambda

885 views
Skip to first unread message

Ales Nosek

unread,
Aug 31, 2017, 4:23:17 PM8/31/17
to vert.x

Hi all,


To briefly introduce myself: I work as a software architect on a microservice-based application implemented mostly in Java. I discovered Vert.x fairly recently but it looks to me that it could be an awesome fit for our application.


Coming to my problem now. I’d like to be able to create a RESTful service that would be both:

  1. Deployed as a standalone service leveraging the Vert.x HTTP server

  2. Deployed as a Lambda function in AWS


I’m thinking about creating an adaptor that would create an HttpServerRequest based upon the HTTP request data passed in by AWS Lambda. I could then call router.accept(httpServerRequest) to process the request the same way as the standalone service would do. Here is some example code:


public class MyService implements com.amazonaws.services.lambda.runtime.RequestStreamHandler {

   
public void handleRequest(InputStream input, OutputStream output, Context context) {
       
Vertx vertx = Vertx.factory.vertx();

       
Router router = Router.router(vertx);      
        router
.route("/some/path1").handler(routingContext -> {
           
// handle request
       
});
        router
.route("/some/path2").handler(routingContext -> {
           
// handle request
       
});

       
HttpServerRequest httpServerRequest = createHttpServerRequest(input, output, context);
        router
.accept(httpServerRequest);
   
}

   
HttpServerRequest createHttpServerRequest(InputStream input, OutputStream output, Context context) {
       
// TODO: Create a Vert.x HttpServerRequest here
   
}        

}



I’m wondering, did somebody do something similar before? Would this be a good approach to solve the problem? I think that it would be great to allow Vert.x web applications to run as Lambda functions. Was searching the web but didn’t find any project that would make this work. I’d be very glad for your comments or suggestions.


Thanks,

Ales

Julien Viet

unread,
Sep 1, 2017, 2:24:51 AM9/1/17
to ve...@googlegroups.com
Hi,

I haven’t done that, however somebody in community blogged about it and we republished it on our blog http://vertx.io/blog/dynamic-routing-in-serverless-microservice-with-vert-x-event-bus/

Julien

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/4e4202d4-249e-4af5-91d1-0ea5b9732d73%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ales Nosek

unread,
Sep 1, 2017, 12:08:57 PM9/1/17
to vert.x
Julien,

Thanks for your response. I read the article on the community blog. In the article they use Vert.x Event Bus to route the request to the respective handler. What I'm trying to do is to leverage io.vertx.ext.web.Router for routing, instead. The reason is that I already have a Router instance configured with all the routing rules. So, I'd like this Router to process my Lambda request. Unfortunately, the router.accept() method takes a parameter of type HttpServerRequest and I don't have an instance of HttpServerRequest when running on Lambda. Instead, Lambda provides InputStream and OutputStream (to read HTTP request and write HTTP response), see also: http://docs.aws.amazon.com/lambda/latest/dg/java-handler-io-type-stream.html

Thanks,
Ales

Julien Viet

unread,
Sep 15, 2017, 11:59:06 AM9/15/17
to vert.x
Hi Chris,

by chance, can you have a look at https://github.com/eclipse/vert.x/pull/2129 ?

Julien
gc.log0

Ales Nosek

unread,
Oct 19, 2017, 2:07:32 AM10/19/17
to vert.x
I solved my problem by creating a AWS Lambda adapter for Vert.x. If anybody is interested, you can find the project on GitHub: https://github.com/noseka1/vertx-aws-lambda

Julien Viet

unread,
Oct 19, 2017, 5:05:47 AM10/19/17
to vert.x
that looks interesting, do you have plan to bridge other API like event bus ?

On 19 Oct 2017, at 08:07, Ales Nosek <ales....@gmail.com> wrote:

I solved my problem by creating a AWS Lambda adapter for Vert.x. If anybody is interested, you can find the project on GitHub: https://github.com/noseka1/vertx-aws-lambda

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.

Ales Nosek

unread,
Oct 23, 2017, 10:51:43 AM10/23/17
to vert.x
Thanks. Currently, I don't have any plans to bridge other APIs.
Reply all
Reply to author
Forward
0 new messages