Skip to content

Commit f104a79

Browse files
committed
Initial README for sample of native web workloads
1 parent ea35706 commit f104a79

File tree

1 file changed

+2
-68
lines changed
  • spring-cloud-function-samples/function-sample-aws-serverless-web-native

1 file changed

+2
-68
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
In this sample, you'll build a native GraalVM image for running web workloads in AWS Lambda.
22

3-
The sample contains a typical Spring MVC application with MVC controllers which will
4-
The sample contains two functions - `uppercase` and `reverse` - so you can see how to route requests. A provided `RoutingFunction` will send messages to a handler function specified in a header named: `spring.cloud.function.definition` (demonstrated in the test section). The routing value can also be passed as an environment variable. If using API Gateway, you can pass this value as an HTTP header.
5-
6-
**Example function definition**
7-
```
8-
@Bean
9-
public Function<String, String> uppercase() {
10-
return v -> {
11-
System.out.println("Uppercasing " + v);
12-
return v.toUpperCase();
13-
};
14-
}
15-
```
16-
17-
> Note: If your function takes a Spring Message as an input parameter (e.g., Function<Message, ..>), the Lambda Context object will be available in the message header `aws-context`. See [AWSLambdaUtils.java](https://github.com/spring-cloud/spring-cloud-function/blob/main/spring-cloud-function-adapters/spring-cloud-function-adapter-aws/src/main/java/org/springframework/cloud/function/adapter/aws/AWSLambdaUtils.java#L67C44-L67C55) for details.
18-
193

204
## To build the sample on macOS (Apple silicon arm64)
215

@@ -28,11 +12,11 @@ Before starting the build, you must clone or download the code in **function-sam
2812
1. Change into the project directory: `spring-cloud-function-samples/function-sample-aws-native`
2913
2. Run the following to build a Docker container image which will be used to create the Lambda function zip file.
3014
```
31-
docker build -t "al2-graalvm19:native-function" .
15+
docker build -t "al2-graalvm21:native-function" .
3216
```
3317
3. Start the container
3418
```
35-
docker run -dit -v `pwd`:`pwd` -w `pwd` -v ~/.m2:/root/.m2 al2-graalvm19:native-function
19+
docker run -dit -v `pwd`:`pwd` -w `pwd` -v ~/.m2:/root/.m2 al2-graalvm21:native-function
3620
```
3721
4. In Docker, open the image terminal.
3822

@@ -45,53 +29,3 @@ Before starting the build, you must clone or download the code in **function-sam
4529

4630
After the build finishes, you need to deploy the function.
4731

48-
49-
### Step 2 - Deploy your function
50-
51-
You will first create the function, and then you will upload the zipped native image from the build process.
52-
53-
**Create the function**
54-
1. Login to the **Amazon Web Services console**.
55-
2. Navigate to the **Lambda service**.
56-
3. Choose `Create Function`.
57-
4. For **function name**, enter `native-func-sample`.
58-
5. For runtime, select `Provide your own bootstrap on Amazon Linux 2`.
59-
6. For architecture, select `arm64`.
60-
7. Choose `Create Function` again.
61-
62-
**Upload the zip image**
63-
1. Choose `Upload from`, then `.zip file`.
64-
2. From the `target` directory, select the .zip file created by the build.
65-
3. Wait for the image to upload.
66-
67-
### Step 3 - Test your function
68-
69-
Your test event will provide the information needed to select the `uppercase` or `reverse` handler functions.
70-
71-
1. From the Lambda console, navigate to the `Test` tab.
72-
2. For test data, enter the following JSON:
73-
```JSON
74-
{
75-
"payload": "hello",
76-
"headers": {
77-
"spring.cloud.function.definition": "uppercase"
78-
}
79-
}
80-
```
81-
3. Choose **Test**.
82-
You should see uppercased output for the payload value: "HELLO"
83-
84-
4. Change the test data to the following JSON:
85-
```JSON
86-
{
87-
"payload": "hello",
88-
"headers": {
89-
"spring.cloud.function.definition": "reverse"
90-
}
91-
}
92-
```
93-
5. Choose **Test**.
94-
You should see reversed output for the payload value: "OLLEH"
95-
96-
97-
**Congratulations!** You have built and deployed a Graal native image to AWS Lambda.

0 commit comments

Comments
 (0)