diff --git a/docs/pom.xml b/docs/pom.xml index bdaa383c1..877bb25e3 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -7,7 +7,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT pom Spring Cloud Function Docs diff --git a/pom.xml b/pom.xml index f36440b1d..3de7e33f1 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ spring-cloud-function-parent Spring Cloud Function Parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT pom diff --git a/spring-cloud-function-adapters/pom.xml b/spring-cloud-function-adapters/pom.xml index a0140d3f6..ff6bdaea4 100644 --- a/spring-cloud-function-adapters/pom.xml +++ b/spring-cloud-function-adapters/pom.xml @@ -10,7 +10,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT spring-cloud-function-adapter-parent diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/README.adoc b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/README.adoc index ebe03bb3e..a1f93459c 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/README.adoc +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/README.adoc @@ -6,4 +6,97 @@ Edit the files in the src/main/asciidoc/ directory instead. This project provides an adapter layer for a Spring Cloud Function application onto AWS Lambda. You can write an app with a single `@Bean` of type `Function`, `Consumer` or `Supplier` and it will be deployable in AWS if you get the JAR file laid out right. The best way to make it work is to include `spring-cloud-function-context` as a dependency, but not the higher level adapters (e.g. `spring-cloud-function-stream`). -Unresolved directive in aws-readme.adoc - include::adapters/aws-intro.adoc[] \ No newline at end of file +The adapter has a couple of generic request handlers that you can use. The most generic is `SpringBootStreamHandler`, which uses a Jackson `ObjectMapper` provided by Spring Boot to serialize and deserialize the objects in the function. There is also a `SpringBootRequestHandler` which you can extend, and provide the input and output types as type parameters (enabling AWS to inspect the class and do the JSON conversions itself). + +If your app has more than one `@Bean` of type `Function` etc. then you can choose the one to use by configuring `function.name` (e.g. as `FUNCTION_NAME` environment variable in AWS). The functions are extracted from the Spring Cloud `FunctionCatalog` (searching first for `Function` then `Consumer` and finally `Supplier`). + +== Notes on JAR Layout + +You don't need the Spring Cloud Function Web or Stream adapter at runtime in Lambda, so you might +need to exclude those before you create the JAR you send to AWS. A Lambda application has to be +shaded, but a Spring Boot standalone application does not, so you can run the same app using 2 +separate jars (as per the sample). The sample app creates 2 jar files, one with an `aws` +classifier for deploying in Lambda, and one executable (thin) jar that includes `spring-cloud-function-web` +at runtime. Spring Cloud Function will try and locate a "main class" for you from the JAR file +manifest, using the `Start-Class` attribute (which will be added for you by the Spring Boot +tooling if you use the starter parent). If there is no `Start-Class` in your manifest you can +use an environment variable or system property `MAIN_CLASS` when you deploy the function to AWS. + +If you are not using the functional bean definitions but relying on Spring Boot's auto-configuration, +then additional transformers must be configured as part of the maven-shade-plugin execution. + +[source, xml] +---- + + org.apache.maven.plugins + maven-shade-plugin + + + org.springframework.boot + spring-boot-maven-plugin + + + + false + true + aws + + + META-INF/spring.handlers + + + META-INF/spring.factories + + + META-INF/spring.schemas + + + + +---- + +== Upload + +Build the sample under `spring-cloud-function-samples/function-sample-aws` and upload the `-aws` jar file to Lambda. The handler can be `example.Handler` or `org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler` (FQN of the class, _not_ a method reference, although Lambda does accept method references). + +---- +./mvnw -U clean package +---- + +Using the AWS command line tools it looks like this: + +---- +aws lambda create-function --function-name Uppercase --role arn:aws:iam::[USERID]:role/service-role/[ROLE] --zip-file fileb://function-sample-aws/target/function-sample-aws-2.0.0.BUILD-SNAPSHOT-aws.jar --handler org.springframework.cloud.function.adapter.aws.SpringBootStreamHandler --description "Spring Cloud Function Adapter Example" --runtime java8 --region us-east-1 --timeout 30 --memory-size 1024 --publish +---- + +The input type for the function in the AWS sample is a Foo with a single property called "value". So you would need this to test it: + +---- +{ + "value": "test" +} +---- + +NOTE: The AWS sample app is written in the "functional" style (as an `ApplicationContextInitializer`). This is much faster on startup in Lambda than the traditional `@Bean` style, so if you don't need `@Beans` (or `@EnableAutoConfiguration`) it's a good choice. Warm starts are not affected. + + +== Type Conversion + +Spring Cloud Function will attempt to transparently handle type conversion between the raw +input stream and types declared by your function. + +For example, if your function signature is as such `Function` we will attempt to convert +incoming stream event to an instance of `Foo`. + +In the event type is not known or can not be determined (e.g., `Function`) we will attempt to +convert an incoming stream event to a generic `Map`. + +==== Raw Input + +There are times when you may want to have access to a raw input. In this case all you need is to declare your +function signature to accept `InputStream`. For example, `Function`. In this case +we will not attempt any conversion and will pass the raw input directly to a function. + + + + diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/pom.xml b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/pom.xml index 5c79a1e31..4ec6d7579 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/pom.xml +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/pom.xml @@ -13,7 +13,7 @@ org.springframework.cloud spring-cloud-function-adapter-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/pom.xml b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/pom.xml index 678dac1c7..1a2822e3e 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/pom.xml +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-azure/pom.xml @@ -13,7 +13,7 @@ org.springframework.cloud spring-cloud-function-adapter-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/pom.xml b/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/pom.xml index fbfcdfb1f..89ae94417 100644 --- a/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/pom.xml +++ b/spring-cloud-function-adapters/spring-cloud-function-adapter-openwhisk/pom.xml @@ -13,7 +13,7 @@ org.springframework.cloud spring-cloud-function-adapter-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-compiler/pom.xml b/spring-cloud-function-compiler/pom.xml index 74a17d720..09b420ccf 100644 --- a/spring-cloud-function-compiler/pom.xml +++ b/spring-cloud-function-compiler/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-context/pom.xml b/spring-cloud-function-context/pom.xml index 3a9705720..8f8c15759 100644 --- a/spring-cloud-function-context/pom.xml +++ b/spring-cloud-function-context/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-core/pom.xml b/spring-cloud-function-core/pom.xml index 424284211..5fee93ddc 100644 --- a/spring-cloud-function-core/pom.xml +++ b/spring-cloud-function-core/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-dependencies/pom.xml b/spring-cloud-function-dependencies/pom.xml index 315d36749..3a90f64b6 100644 --- a/spring-cloud-function-dependencies/pom.xml +++ b/spring-cloud-function-dependencies/pom.xml @@ -10,7 +10,7 @@ spring-cloud-function-dependencies - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT pom Spring Cloud Function Dependencies Spring Cloud Function Dependencies diff --git a/spring-cloud-function-deployer/pom.xml b/spring-cloud-function-deployer/pom.xml index 83e940a23..86272f6c7 100644 --- a/spring-cloud-function-deployer/pom.xml +++ b/spring-cloud-function-deployer/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-deployer/src/it/flux/pom.xml b/spring-cloud-function-deployer/src/it/flux/pom.xml index db2f1e539..9160a1789 100644 --- a/spring-cloud-function-deployer/src/it/flux/pom.xml +++ b/spring-cloud-function-deployer/src/it/flux/pom.xml @@ -18,7 +18,7 @@ 1.8 - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT 1.0.17.RELEASE diff --git a/spring-cloud-function-deployer/src/it/support/pom.xml b/spring-cloud-function-deployer/src/it/support/pom.xml index a9d0a065a..f730c857f 100644 --- a/spring-cloud-function-deployer/src/it/support/pom.xml +++ b/spring-cloud-function-deployer/src/it/support/pom.xml @@ -18,7 +18,7 @@ 1.8 - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT 1.0.17.RELEASE diff --git a/spring-cloud-function-kotlin/pom.xml b/spring-cloud-function-kotlin/pom.xml index 3e88456a0..15563661c 100644 --- a/spring-cloud-function-kotlin/pom.xml +++ b/spring-cloud-function-kotlin/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-samples/function-sample-aws-custom/pom.xml b/spring-cloud-function-samples/function-sample-aws-custom/pom.xml index 2575349dd..e932dc5b3 100644 --- a/spring-cloud-function-samples/function-sample-aws-custom/pom.xml +++ b/spring-cloud-function-samples/function-sample-aws-custom/pom.xml @@ -17,7 +17,7 @@ 1.8 1.0.21.RELEASE - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-samples/function-sample-aws/pom.xml b/spring-cloud-function-samples/function-sample-aws/pom.xml index aa51e3986..505b2b10e 100644 --- a/spring-cloud-function-samples/function-sample-aws/pom.xml +++ b/spring-cloud-function-samples/function-sample-aws/pom.xml @@ -25,7 +25,7 @@ 1.8 1.0.17.RELEASE 2.0.2 - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT example.Config diff --git a/spring-cloud-function-samples/function-sample-compiler/pom.xml b/spring-cloud-function-samples/function-sample-compiler/pom.xml index 82121daea..5e684dc29 100644 --- a/spring-cloud-function-samples/function-sample-compiler/pom.xml +++ b/spring-cloud-function-samples/function-sample-compiler/pom.xml @@ -20,7 +20,7 @@ 1.8 - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT 3.1.2.RELEASE 1.0.17.RELEASE diff --git a/spring-cloud-function-samples/function-sample-pof/pom.xml b/spring-cloud-function-samples/function-sample-pof/pom.xml index 1678e8bc8..866daee53 100644 --- a/spring-cloud-function-samples/function-sample-pof/pom.xml +++ b/spring-cloud-function-samples/function-sample-pof/pom.xml @@ -22,7 +22,7 @@ UTF-8 1.8 3.1.2.RELEASE - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-samples/function-sample-pojo/pom.xml b/spring-cloud-function-samples/function-sample-pojo/pom.xml index a41ef3801..5e0d2b00b 100644 --- a/spring-cloud-function-samples/function-sample-pojo/pom.xml +++ b/spring-cloud-function-samples/function-sample-pojo/pom.xml @@ -20,7 +20,7 @@ 1.8 - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT 1.0.21.RELEASE diff --git a/spring-cloud-function-samples/function-sample-spring-integration/pom.xml b/spring-cloud-function-samples/function-sample-spring-integration/pom.xml index 7fad67d93..e5f93fd6a 100644 --- a/spring-cloud-function-samples/function-sample-spring-integration/pom.xml +++ b/spring-cloud-function-samples/function-sample-spring-integration/pom.xml @@ -20,7 +20,7 @@ UTF-8 UTF-8 1.8 - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-samples/function-sample-task/pom.xml b/spring-cloud-function-samples/function-sample-task/pom.xml index d8a704fe7..cb8a83053 100644 --- a/spring-cloud-function-samples/function-sample-task/pom.xml +++ b/spring-cloud-function-samples/function-sample-task/pom.xml @@ -20,7 +20,7 @@ 1.8 - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT 1.0.10.RELEASE 3.1.2.RELEASE diff --git a/spring-cloud-function-samples/function-sample/pom.xml b/spring-cloud-function-samples/function-sample/pom.xml index c1020668f..f2bee47d6 100644 --- a/spring-cloud-function-samples/function-sample/pom.xml +++ b/spring-cloud-function-samples/function-sample/pom.xml @@ -20,7 +20,7 @@ 1.8 - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT 1.0.17.RELEASE diff --git a/spring-cloud-function-samples/pom.xml b/spring-cloud-function-samples/pom.xml index 2e55e9b1c..90aaa1522 100644 --- a/spring-cloud-function-samples/pom.xml +++ b/spring-cloud-function-samples/pom.xml @@ -11,7 +11,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-task/pom.xml b/spring-cloud-function-task/pom.xml index dd05b0632..0e99e9124 100644 --- a/spring-cloud-function-task/pom.xml +++ b/spring-cloud-function-task/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-function-web/pom.xml b/spring-cloud-function-web/pom.xml index 0effd30b8..cc73496e8 100644 --- a/spring-cloud-function-web/pom.xml +++ b/spring-cloud-function-web/pom.xml @@ -12,7 +12,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT diff --git a/spring-cloud-starter-function-web/pom.xml b/spring-cloud-starter-function-web/pom.xml index 52f2d3aa4..96f080bf3 100644 --- a/spring-cloud-starter-function-web/pom.xml +++ b/spring-cloud-starter-function-web/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT .. spring-cloud-starter-function-web diff --git a/spring-cloud-starter-function-webflux/pom.xml b/spring-cloud-starter-function-webflux/pom.xml index dd8abfeec..49e9c012e 100644 --- a/spring-cloud-starter-function-webflux/pom.xml +++ b/spring-cloud-starter-function-webflux/pom.xml @@ -6,7 +6,7 @@ org.springframework.cloud spring-cloud-function-parent - 2.1.1.RELEASE + 2.1.1.BUILD-SNAPSHOT spring-cloud-starter-function-webflux spring-cloud-starter-function-webflux