https://github.com/umaxcode/sam-springboot-lambda-with-dynamodb
A spring boot crud project deployed on AWS lambda with DynamoDB integration using SAM
https://github.com/umaxcode/sam-springboot-lambda-with-dynamodb
Last synced: 10 months ago
JSON representation
A spring boot crud project deployed on AWS lambda with DynamoDB integration using SAM
- Host: GitHub
- URL: https://github.com/umaxcode/sam-springboot-lambda-with-dynamodb
- Owner: UmaxCode
- Created: 2024-12-23T12:57:12.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-10T08:55:50.000Z (about 1 year ago)
- Last Synced: 2025-02-11T09:54:05.458Z (12 months ago)
- Language: Java
- Homepage:
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# springboot-crud-with-lambda serverless API
The springboot-crud-with-lambda project, created with [`aws-serverless-java-container`](https://github.com/aws/serverless-java-container).
The starter project defines a simple `/ping` resource that can accept `GET` requests with its tests.
The project folder also includes a `template.yml` file. You can use this [SAM](https://github.com/awslabs/serverless-application-model) file to deploy the project to AWS Lambda and Amazon API Gateway or test in local with the [SAM CLI](https://github.com/awslabs/aws-sam-cli).
## Pre-requisites
* [AWS CLI](https://aws.amazon.com/cli/)
* [SAM CLI](https://github.com/awslabs/aws-sam-cli)
* [Gradle](https://gradle.org/) or [Maven](https://maven.apache.org/)
## Building the project
You can use the SAM CLI to quickly build the project
```bash
$ mvn archetype:generate -DartifactId=springboot-crud-with-lambda -DarchetypeGroupId=com.amazonaws.serverless.archetypes -DarchetypeArtifactId=aws-serverless-jersey-archetype -DarchetypeVersion=2.1.0 -DgroupId=org.umaxcode -Dversion=1.0-SNAPSHOT -Dinteractive=false
$ cd springboot-crud-with-lambda
$ sam build
Building resource 'SpringbootCrudWithLambdaFunction'
Running JavaGradleWorkflow:GradleBuild
Running JavaGradleWorkflow:CopyArtifacts
Build Succeeded
Built Artifacts : .aws-sam/build
Built Template : .aws-sam/build/template.yaml
Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided
```
## Testing locally with the SAM CLI
From the project root folder - where the `template.yml` file is located - start the API with the SAM CLI.
```bash
$ sam local start-api
...
Mounting com.amazonaws.serverless.archetypes.StreamLambdaHandler::handleRequest (java11) at http://127.0.0.1:3000/{proxy+} [OPTIONS GET HEAD POST PUT DELETE PATCH]
...
```
Using a new shell, you can send a test ping request to your API:
```bash
$ curl -s http://127.0.0.1:3000/ping | python -m json.tool
{
"pong": "Hello, World!"
}
```
## Deploying to AWS
To deploy the application in your AWS account, you can use the SAM CLI's guided deployment process and follow the instructions on the screen
```
$ sam deploy --guided
```
Once the deployment is completed, the SAM CLI will print out the stack's outputs, including the new application URL. You can use `curl` or a web browser to make a call to the URL
```
...
-------------------------------------------------------------------------------------------------------------
OutputKey-Description OutputValue
-------------------------------------------------------------------------------------------------------------
SpringbootCrudWithLambdaApi - URL for application https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/Prod/pets
-------------------------------------------------------------------------------------------------------------
```
Copy the `OutputValue` into a browser or use curl to test your first request:
```bash
$ curl -s https://xxxxxxx.execute-api.us-west-2.amazonaws.com/Prod/ping | python -m json.tool
{
"pong": "Hello, World!"
}
```