Code Monkey home page Code Monkey logo

spring-aws-lambda's Introduction

spring-aws-lambda

Build Status Maven Central

A Java library to enable core Spring Framework dependency injection support and eliminate some boilerplate around AWS Lambda.

Usage

When using Java with AWS Lambda, AWS requires you to either implement one of their base interfaces (RequestHandler or RequestStreamHandler), or provide a class with a single method handle(T input, Context context). This library leverages the interface-based approach. When deploying the function, you need to point Lambda to your "main handler" class, which serves as the entry point to your application.

The main usage is simple: import this library as a dependency and extend one of the main abstract classes in me.ccampo.spring.aws.lambda as your main handler class. You will be forced to implement the getApplicationContext method, which is where you will provide the instance to your Spring application context class, which will be used throughout the rest of the application.

Once you have provided an ApplicationContext, you can use Spring's dependency injection features anywhere besides in your MainHandler class. This means you can take the annotation driven approach, use autowiring, etc.

The abstract handler classes in this library actually use the provided ApplicationContext instance to find a bean of type RequestHandler (Lambda's main interface) and call it's handleRequest method, so most of your application logic should not be in your MainHandler class, but rather in a separate bean of type RequestHandler.

The main pattern I recommend is creating a fairly empty MainHandler class that implements one of this library's interfaces, supplies an ApplicationContext, and then does nothing else. Additionally, you create another implementation of RequestHandler and register it as a bean (either manually in your Spring configuration or using annotations such as @Component). This custom RequestHandler can then take advantage of all of Spring's dependency injection tools. You are free to implement your application logic in there, or split it out over several, loosely coupled classes, using Spring dependency injection to wire it all together.

See the example directory for some a simple example of this pattern.

If you have any questions/comments/issues, please feel free to use the GitHub issue tracker to report them.

Best, /cc

www.ccampo.me

Dependency Information

Found on Maven Central (http://search.maven.org)

Gradle:

compile 'me.ccampo:spring-aws-lambda:1.1.0'

Maven:

<dependency>
  <groupId>me.ccampo</groupId>
  <artifactId>spring-aws-lambda</artifactId>
  <version>1.1.0</version>
</dependency>

Development

To Build:

For -nix and OSX:

./gradlew build

For Windows:

gradlew.bat build

Requires Java 1.8

spring-aws-lambda's People

Contributors

ccampo133 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.