Showing posts with label announce. Show all posts
Showing posts with label announce. Show all posts

Saturday, November 28, 2015

Groovy framework for AWS lambda

I was playing with AWS lambda recently and I find it pretty exciting. It is cheap, does not require any maintenance and it is simple. The biggest problem I found so far, is lack of tooling. AWS has web UI which does what it supposed to do, but is far from pleasant. AWS command line tools and API are much better, but are AWS centric. So, I have created tool to work with AWS lambda. It uses some convention now, but can be adjusted to whatever feels right for specific situation, idea is that it is just one script with few lines of code. Basically, it does 2 things: uploads application and local testing. I have created small example that illustrates how and what it does.

Example is trivial application that increments number by clicking on button. It is SPA, with static client in S3 and two API functions add and get.

All lambda code is just single Groovy script. It consists of router function, dependencies and logic. Router function is what will be mapped to lambda. It is function that accepts map and returns map. Input map can be plain request JSON, or some additional parameters can be injected at API gateway. Even for this trivial case it was a good idea and I injected configuration parameters - AWS access and secret keys and region for DynamoDB access, so they are hidden at admin level and are environment specific. Simplest way to do routing is just by using some designated parameter, in this example, it is called "function". Doing it with real URI will need AWS configuration, and it is not very convenient and flexible.

In this simple example, router script does logic, but for more complex cases it is better to be just router and logic would be in dependencies.

During packaging Groovy script is compiled and packaged together with all dependencies into uberjar which is required by AWS. After that, it is uploaded via AWS API.

Development can be done and tested locally by using mock server. Mock server mimics AWS, parses input into JSON like lambda, injects parameters like API gateway, includes Access-Control-Allow-Origin and separates configuration via config.js, supports debug and reloading.

Friday, April 19, 2013

Lightweight Groovy HTTP server for testing

Recently, I was looking for really lightweight HTTP server for integration and functional testing. Minimalistic web servers looks like popular topic now and there is a bunch of them available, like Ratpack, Graffiti or Spark. But none of them looked like what I needed: really small, expressive and convenient for tests. One, that was looking best is HttpServer from JDK, but it's horrible boilerplate code is ugly even by the Java standards, so finally I decided to write one myself.

And this is the result https://github.com/dmitart/lightweightest.

It is based on JDK HttpServer, just less verbose API and tests oriented, just check examples in the README. Enjoy. But don't put it in production.

Friday, March 5, 2010

Let's start

Today I start this blog. I have created articles here and there before, but never in some organized way. So I'll try to put everything about programming, software and internet that can be related to my professional development.