https://github.com/maciejwalkowiak/spring-cloud-function-aws-sam-sample
Sample Spring Cloud Function application running on AWS deployed with AWS SAM
https://github.com/maciejwalkowiak/spring-cloud-function-aws-sam-sample
Last synced: 7 months ago
JSON representation
Sample Spring Cloud Function application running on AWS deployed with AWS SAM
- Host: GitHub
- URL: https://github.com/maciejwalkowiak/spring-cloud-function-aws-sam-sample
- Owner: maciejwalkowiak
- Created: 2022-07-28T09:58:22.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-07-28T10:07:06.000Z (about 3 years ago)
- Last Synced: 2025-01-07T22:53:36.693Z (9 months ago)
- Language: Java
- Size: 60.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Spring Cloud Function AWS SAM Sample
Sample project containing all required configuration to run Spring Cloud Function on AWS with AWS SAM.
**NOTE**: this is a sample that runs on Java 11 runtime. It does not cover running a native image. For more complex sample projects go to https://github.com/aws-samples/serverless-java-frameworks-samples/tree/main/springboot
## Deploy the sample application
The Serverless Application Model Command Line Interface (SAM CLI) is an extension of the AWS CLI that adds functionality for building and testing Lambda applications. It uses Docker to run your functions in an Amazon Linux environment that matches Lambda. It can also emulate your application's build environment and API.
To use the SAM CLI, you need the following tools.
* SAM CLI - [Install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)
* Java11 - [Install the Java 11](https://docs.aws.amazon.com/corretto/latest/corretto-11-ug/downloads-list.html)
* Maven - [Install Maven](https://maven.apache.org/install.html)
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)To build and deploy your application for the first time, run the following in your shell:
```bash
./mvn package
sam deploy --guided
```The first command will build the source of your application. The second command will package and deploy your application to AWS, with a series of prompts:
You can find your API Gateway Endpoint URL in the output values displayed after deployment.
The SAM CLI can also emulate your application's API. Use the `sam local start-api` to run the API locally on port 3000.
```bash
$ sam local start-api
$ curl http://localhost:3000/hello
```The SAM CLI reads the application template to determine the API's routes and the functions that they invoke. The `Events` property on each function's definition includes the route and method for each path.
```yaml
Events:
HelloWorld:
Type: Api
Properties:
Path: /hello
Method: get
```## Add a resource to your application
The application template uses AWS Serverless Application Model (AWS SAM) to define application resources. AWS SAM is an extension of AWS CloudFormation with a simpler syntax for configuring common serverless application resources such as functions, triggers, and APIs. For resources not included in [the SAM specification](https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md), you can use standard [AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html) resource types.## Fetch, tail, and filter Lambda function logs
To simplify troubleshooting, SAM CLI has a command called `sam logs`. `sam logs` lets you fetch logs generated by your deployed Lambda function from the command line. In addition to printing the logs on the terminal, this command has several nifty features to help you quickly find the bug.
`NOTE`: This command works for all AWS Lambda functions; not just the ones you deploy using SAM.
```bash
$ sam logs --stack-name --tail
```You can find more information and examples about filtering Lambda function logs in the [SAM CLI Documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-logging.html).
## Cleanup
To delete the sample application that you created, use the AWS CLI. Assuming you used your project name for the stack name, you can run the following:
```bash
$ sam delete --stack-name
```