Serverless Boilerplate for Spring Framework and AWS Lambda
Do you love Spring MVC? Are you interested in developing serverless applications with AWS Lambda? Well, then this is the boilerplate for you! This project demonstrates how to run a Spring MVC application on AWS Lambda, and how to write tests for said appplication. For the data store, this uses a simple in-memory Map to store Article
objects by ID. For a real-world serverless application, I would suggest using DynamoDB.
This project would not be possible without aws-serverless-java-container.
$ gradle shadowJar
-
Create Lambda function
- Triggers: None
- Runtime:
Java 8 Runtime
- Handler:
com.joeyvmason.serverless.spring.application.LambdaHandler
- Role:
Create new Role from Template
- Policy:
Simple Microservices permissions
- Jar:
build/libs/serverless-spring-boilerplate-all.jar
- Memory: Set to max
-
Create API Gateway API
- Create Resource
- Configure as proxy resource:
True
- Resource name:
proxy
- Resource Path:
{proxy+}
- Configure as proxy resource:
- Map resource to Lambda function
- Select
Integration Request
- Integration Type:
Lambda Function
- Use Lambda Proxy Integration:
True
- Select region and Lambda function
Actions
->Deploy API
- Select
- Create Resource
-
Test
-
Create an article
- Endpoint:
/articles
- Method:
POST
- Example:
curl -H "Content-Type: application/json" -X POST -d '{"title": "some title", "body": "some body"}' {invoke_url}/{stage}/articles
- Endpoint:
-
Get all articles
- Endpoint:
/articles
- Method:
GET
- Example:
curl {invoke_url}/{stage}/articles
- Endpoint:
-
Get article by id
- Endpoint:
/articles/{article_id}
- Method:
GET
- Example:
curl {invoke_url}/{stage}/articles/{article_id}
- Endpoint:
-
Update an article
- Endpoint:
/articles/{article_id}
- Method:
PUT
- Example:
curl -H "Content-Type: application/json" -X PUT -d '{"title": "new title", "body": "new body"}' {invoke_url}/{stage}/articles/{article_id}
- Endpoint:
-