https://github.com/visionarts/power-jambda
The java serverless microframework for AWS Lambda - Java + Lambda = Power Jambda
https://github.com/visionarts/power-jambda
api-gateway aws aws-lambda jackson java-serverless-microframework json log4j2 rest-api serverless-application-model
Last synced: about 2 months ago
JSON representation
The java serverless microframework for AWS Lambda - Java + Lambda = Power Jambda
- Host: GitHub
- URL: https://github.com/visionarts/power-jambda
- Owner: visionarts
- License: apache-2.0
- Created: 2017-08-02T07:41:07.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2025-06-24T07:19:47.000Z (9 months ago)
- Last Synced: 2025-07-07T05:59:04.271Z (8 months ago)
- Topics: api-gateway, aws, aws-lambda, jackson, java-serverless-microframework, json, log4j2, rest-api, serverless-application-model
- Language: Java
- Homepage:
- Size: 341 KB
- Stars: 12
- Watchers: 7
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Power-Jambda
[](https://raw.githubusercontent.com/visionarts/power-jambda/master/LICENSE)
[](https://github.com/visionarts/power-jambda/actions/workflows/action.yml)
[](https://codecov.io/gh/visionarts/power-jambda)
[](https://maven-badges.herokuapp.com/maven-central/com.visionarts/power-jambda-pom)
[](http://javadoc.io/doc/com.visionarts/power-jambda-core)
The java serverless microframework for RESTful API allows you to quickly develop applications that use Amazon API Gateway and AWS Lambda.
## Getting Started
#### Maven installation ####
The recommended way to get started using this framework
in your project is with a dependency management system
```xml
com.visionarts
power-jambda-core
0.9.17
```
#### Quick Start ####
Here you create an Application class to have main Lambda function handler:
src/main/java/sample/SampleApplication.java
```Java
/**
* Sample application.
*/
public class SampleApplication implements RequestStreamHandler {
@Override
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
try {
LambdaApplication.run(SampleApplication.class, input, output, context);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
```
Now you can create a action class for handling RESTful API request:
src/main/java/sample/action/SampleAction.java
```Java
/**
* Sample action class.
*/
@Route(resourcePath = "/sample", methods = HttpMethod.POST)
public class SampleAction extends AbstractLambdaAction {
@Override
public Class actionBodyType() {
return SampleMessageBody.class;
}
@Override
public SampleMessageBody handle(ActionRequest request, Context context) {
// echo back
SampleMessageBody res = new SampleMessageBody();
res.message = request.getBody().message;
res.name = request.getBody().name;
return res;
}
@ExceptionHandler(IllegalArgumentException.class)
public ResponseEntity handleException(IllegalArgumentException e, Context context) {
SampleErrorModel body = new SampleErrorModel();
body.error = "BadRequest";
body.code = 400001;
body.description = e.getMessage();
return new ResponseEntity()
.body(body)
.statusCode(400);
}
}
```
The class is annotated a **@Route**, meaning it’s ready for use by AWS Lambda to handle requests. **@Route** maps 'POST /sample' to this action class.
When invoked from API Gateway using curl on the command line, the handle method returns 200 OK, including a json content serialized SampleMessageBody('application/json').
See [RESTful API example](samples/simple-case) for more information.
### Tutorial: Return RESTful API response
TBD
### Tutorial: Error Handling
TBD
### Tutorial: Customizing the HTTP Response
TBD
### Tutorial: CORS support
By default, injects the ``Access-Control-Allow-Origin: *`` header to your responses,
including error responses return from action.
If more control of the CORS headers is desired, set the ``cors``
parameter in your ``@Route`` to an instance of ``CorsConfiguration``.
The ``CorsConfiguration`` interface can be implemented as follows.
```Java
public class MyCorsConfig implements CorsConfiguration {
@Override
public Optional getAllowOrigin() {
return Optional.of("http://www.example.com");
}
@Override
public Optional getAllowCredentials() {
return Optional.of(true);
}
}
```
```Java
@Route(resourcePath = "/sample", methods = HttpMethod.POST, cors = MyCorsConfig.class)
public class SampleAction extends AbstractLambdaAction {
}
```
If you disable CORS support, specify ``cors = NoneCorsConfiguration.class`` in your ``@Route``.
## Building From Source
Once you check out the code from GitHub, you can build it using Maven.
```sh
./mvnw clean install
```
License
-------
Copyright (C) 2017 [Visionarts, Inc](https://www.visionarts.co.jp/)
Distributed under the Apache License v2.0. See the file LICENSE.
Development and Contribution
----------------------------
We will open for contributions.