


























One option to deploy serverless applications built with AWS Lambda is to use AWS SAM - a framework that comes with:
To create new SAM project, you can simply call sam init and then choose one of the available templates for variety of programming languages - including Java.
Java templates baked into SAM CLI are literally pure Java - no frameworks other than the standard AWS Lambda SDK are included.
To speed up creating Spring Cloud Function based projects, I created a template a custom SAM template: https://github.com/maciejwalkowiak/aws-sam-spring-cloud-function-template.
Calling following command:
$ sam init --location gh:maciejwalkowiak/aws-sam-spring-cloud-function-template.. generates:
java11 runtime (no GraalVM native image yet)$ tree .
.
├── mvnw
├── mvnw.cmd
├── pom.xml
├── src
│ ├── main
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── demo
│ │ ├── FunctionApplication.java
│ │ └── HelloWorldFunction.java
│ └── test
│ └── java
│ └── com
│ └── example
│ └── demo
│ └── FunctionApplicationTests.java
└── template.yamlNow you can build project with ./mvnw package and execute sam deploy to deploy function to AWS or sam local start-api to start function locally.
You might be wondering how is this project really different from regular SAM template for Java, except of course using Spring Cloud Function in the Java code. There are only few - but important things to notice:
template.yml has to be set to org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequestSPRING_CLOUD_FUNCTION_DEFINITION environment variable to tell the framework which function to call (otherwise it will try to figure out based on the message but this requires more/different configuration)spring-boot-thin-layout in spring-boot-maven-plugin configurationIf you believe this template can be improved, you are welcome to create an issue and even more welcome to submit a PR to https://github.com/maciejwalkowiak/aws-sam-spring-cloud-function-template.
In the future, I plan to extend this template with a question about the target runtime and give users an option to choose between java11 and a custom runtime running GraalVM native image.
Let's stay in touch and follow me on Twitter: @maciejwalkowiak
Subscribe to RSS feed ![]()
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。