Jrestless
Run JAX-RS applications on AWS Lambda using Jersey. Supports Spring 4.x. The serverless framework can be used for deployment.
Install / Use
/learn @bbilger/JrestlessREADME
JRestless
JRestless allows you to create serverless applications using JAX-RS.

Table of Contents
- Description
- Motivation
- Features
- Function Types
- Usage Example
- Modules
- Release History
- Alternative Projects
- Limitations
- Meta
Description
JRestless is a framework allowing you to build serverless JAX-RS applications or rather to run JAX-RS applications in FasS (Function as a Service) environments like AWS Lambda. This is achieved by providing a generic Jersey container that handles requests in the form of POJOs. For each FaaS environment there is a separate module acting as an integration layer between the actual environment and the generic Jersey container.
Since this framework is just a wrapper around or rather a container for Jersey, you can use almost all JAX-RS features plus Jersey's custom extensions like Spring integration - not Spring MVC, though since this functionality is provided by JAX-RS itself.
Supported Environments:
- AWS Lambda
- OpenWhisk (experimental/in progress)
- Fn Project
Motivation
The motivation for this project is to avoid a cloud vendor lock-in and to allow developers to run and test their code locally.
Features
- Almost all JAX-RS features can be used (JSON/XML/text/... requests/responses, container request/response filters, etc.). Example: aws-gateway-showcase
- Jersey extensions can be used. For example:
- Spring: aws-gateway-spring
- CDI: aws-gateway-cdi
- Guice: aws-gateway-guice
- AWS Gateway Functions can also consume and produce binary data. Example: aws-gateway-binary
- AWS Gateway Functions use the data added to the request by authorizers (Custom Authorizers or Cognito User Pool Authorizers) to create a Principal (CustomAuthorizerPrincipal or CognitoUserPoolAuthorizerPrincipal) within the SecurityContext containing all claims. Examples: aws-gateway-security-cognito-authorizer and aws-gateway-security-custom-authorizer
- AWS Gateway Functions can use a CORS filter. Example: aws-gateway-cors
- Injection of provider and/or function type specific values via
@javax.ws.rs.core.Contextinto resources and endpoints:- All AWS functions can inject
com.amazonaws.services.lambda.runtime.Context. - AWS Gateway Functions can also inject the raw request GatewayRequest
- AWS Service Functions can also inject the raw request ServiceRequest
- AWS SNS Functions can also inject the raw request SNSRecord
- All AWS functions can inject
- It's worth mentioning that AWS Gateway Functions is designed to be used with API Gateway's proxy integration type for Lambda Functions. So there are no limitations on the status code, the headers and the body you return.
Function Types
AWS
- Gateway Functions are AWS Lambda functions that get invoked by AWS API Gateway. Usage example: aws-gateway-usage-example. Read More....
- Service Functions are AWS Lambda functions that can either be invoked by other AWS Lambda functions or can be invoked directly through the AWS SDK. The point is that you don't use AWS API Gateway. You can abstract the fact that you invoke an AWS Lambda function away by using a special feign client (jrestless-aws-service-feign-client). Usage example: aws-service-usage-example. Read More....
- SNS functions are AWS Lambda function that get invoked by SNS. This allow asynchronous calls to other Lambda functions. So when one Lambda function publishes a message to one SNS topic, SNS can then invoke all (1-N) subscribed Lambda functions. Usage example: aws-sns-usage-example. Read More....
Fn Project
- Http Functions handle HTTP formatted requests Read More...
Note: the framework is split up into multiple modules, so you choose which functionality you actually want to use. See Modules
Usage Example
AWS Usage Example
All examples, including the following one, can be found in a separate repository: https://github.com/bbilger/jrestless-examples
JRestless does not depend on the serverless framework but it simplifies the necessary AWS configuration tremendously and will be used for this example.
Install serverless (>= 1.0.2) as described in the docs https://serverless.com/framework/docs/guide/installing-serverless/
Setup your AWS account as described in the docs https://serverless.com/framework/docs/providers/aws/guide/credentials/
Create a new function using serverless
mkdir aws-gateway-usage-example
cd aws-gateway-usage-example
serverless create --template aws-java-gradle --name aws-gateway-usage-example
rm -rf src/main/java # remove the classes created by the template
mkdir -p src/main/java/com/jrestless/aws/examples # create the package structure
Replace serverless.yml with the following contents:
service: aws-gateway-usage-example-service
provider:
name: aws
runtime: java8
stage: dev
region: eu-central-1
package:
artifact: build/distributions/aws-gateway-usage-example.zip
functions:
sample:
handler: com.jrestless.aws.examples.RequestHandler
events:
- http:
path: samp
