Skip to content

Commit 0bd8b00

Browse files
committed
Updated to M2 of the aws-serverless-java-container
1 parent e4609ce commit 0bd8b00

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

apigw-lambda-snapstart/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,35 @@ to improve startup performance.
88

99
Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/apigw-lambda-snapstart.
1010

11+
## Spring Web support in Lambda
12+
13+
This pattern uses the Spring Web ```@Controller``` to support different REST endpoints in the same Lambda function.
14+
There are two supported ways to achieve this with the AWS Serverless Java Container.
15+
16+
### Delegating the handler to Spring
17+
18+
The first is to specify a Spring class as the function handler and reference the SpringBootApplication class as an
19+
environment variable.
20+
21+
```yaml
22+
Type: AWS::Serverless::Function
23+
Properties:
24+
Handler: com.amazonaws.serverless.proxy.spring.SpringDelegatingLambdaContainerHandler
25+
...
26+
Environment:
27+
Variables:
28+
MAIN_CLASS: com.unicorn.store.StoreApplication
29+
```
30+
31+
This is useful as you don't need to make any changes to your existing application to run it in Lambda.
32+
33+
### Starting Spring in your own handler
34+
35+
An alternative is to create your own handler and start Spring within it. The class ```StreamLambdaHandler``` is an
36+
example of this.
37+
38+
This is useful when you want control over the handler method, for example to add an annotation.
39+
1140
## Requirements
1241

1342
* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.

apigw-lambda-snapstart/UnicornFunction/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
<dependency>
4646
<groupId>com.amazonaws.serverless</groupId>
4747
<artifactId>aws-serverless-java-container-springboot3</artifactId>
48-
<version>2.0.0-M1</version>
48+
<version>2.0.0-M2</version>
4949
</dependency>
5050

5151
<dependency>

apigw-lambda-snapstart/template.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ Resources:
1818
UnicornStoreSpringFunction:
1919
Type: AWS::Serverless::Function
2020
Properties:
21-
Handler: com.unicorn.store.StreamLambdaHandler
21+
Handler: com.amazonaws.serverless.proxy.spring.SpringDelegatingLambdaContainerHandler
2222
CodeUri: UnicornFunction
2323
Tracing: Active
2424
Environment:
2525
Variables:
26+
MAIN_CLASS: com.unicorn.store.StoreApplication
2627
AWS_SERVERLESS_JAVA_CONTAINER_INIT_GRACE_TIME: 500
2728
UNICORN_TABLE_NAME: !Ref UnicornTable
2829
POWERTOOLS_LOG_LEVEL: INFO

0 commit comments

Comments
 (0)