Skip to content

Commit ab493c0

Browse files
author
Vadym Kazulkin
committed
improved readme
1 parent 47d08a7 commit ab493c0

File tree

2 files changed

+96
-2
lines changed

2 files changed

+96
-2
lines changed

spring-boot-3.2-docker-image-with-crac/src/main/java/software/amazonaws/example/product/handler/GetProductByIdHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
package software.amazonaws.example.product.handler;
55

6+
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
69
import java.util.Optional;
710
import java.util.Properties;
811
import java.util.function.Function;
@@ -33,6 +36,14 @@ public class GetProductByIdHandler implements Function<APIGatewayProxyRequestEve
3336

3437
public APIGatewayProxyResponseEvent apply(APIGatewayProxyRequestEvent requestEvent) {
3538

39+
Path filePath = Path.of("/mnt/msg/crac/dump4.log");
40+
try {
41+
String content = Files.readString(filePath);
42+
logger.info("crac dump" +content);
43+
} catch (IOException e) {
44+
logger.info("error reading dmup" +e.getMessage());
45+
}
46+
3647
Properties prop = System.getProperties();
3748
logger.info ("JVM Vendor : " + prop.getProperty("java.vendor") );
3849
String id = requestEvent.getPathParameters().get("id");

spring-boot-3.2-docker-image-with-crac/template.yaml

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,76 @@ Globals:
1515
MemorySize: 1024
1616
Environment:
1717
Variables:
18-
JAVA_TOOL_OPTIONS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Dspring.context.checkpoint=onRefresh -XX:CRaCCheckpointTo=/tmp/crac"
1918
MAIN_CLASS: software.amazonaws.Application
2019
PRODUCT_TABLE_NAME: !Ref ProductsTable
2120

2221
Resources:
22+
23+
EfsLambdaVpc:
24+
Type: AWS::EC2::VPC
25+
Properties:
26+
CidrBlock: "10.0.0.0/16"
27+
EfsLambdaSecurityGroup:
28+
Type: AWS::EC2::SecurityGroup
29+
Properties:
30+
GroupDescription: "EFS + Lambda on SAM Security Group"
31+
VpcId: !Ref EfsLambdaVpc
32+
SecurityGroupEgress:
33+
- CidrIp: "0.0.0.0/0"
34+
FromPort: 0
35+
ToPort: 65535
36+
IpProtocol: tcp
37+
SecurityGroupIngress:
38+
- CidrIp: "0.0.0.0/0"
39+
FromPort: 0
40+
ToPort: 65535
41+
IpProtocol: tcp
42+
EfsLambdaSubnetA:
43+
Type: AWS::EC2::Subnet
44+
Properties:
45+
VpcId: !Ref EfsLambdaVpc
46+
AvailabilityZone: !Select [ 0, !GetAZs '' ]
47+
MapPublicIpOnLaunch: false
48+
CidrBlock: "10.0.0.0/24"
49+
EfsLambdaSubnetB:
50+
Type: AWS::EC2::Subnet
51+
Properties:
52+
VpcId: !Ref EfsLambdaVpc
53+
AvailabilityZone: !Select [ 1, !GetAZs '' ]
54+
MapPublicIpOnLaunch: false
55+
CidrBlock: "10.0.1.0/24"
56+
EfsFileSystem:
57+
Type: AWS::EFS::FileSystem
58+
MountTargetA:
59+
Type: AWS::EFS::MountTarget
60+
Properties:
61+
FileSystemId: !Ref EfsFileSystem
62+
SubnetId: !Ref EfsLambdaSubnetA
63+
SecurityGroups:
64+
- !Ref EfsLambdaSecurityGroup
65+
MountTargetB:
66+
Type: AWS::EFS::MountTarget
67+
Properties:
68+
FileSystemId: !Ref EfsFileSystem
69+
SubnetId: !Ref EfsLambdaSubnetB
70+
SecurityGroups:
71+
- !Ref EfsLambdaSecurityGroup
72+
AccessPoint:
73+
Type: AWS::EFS::AccessPoint
74+
Properties:
75+
FileSystemId: !Ref EfsFileSystem
76+
PosixUser:
77+
Gid: "1000"
78+
Uid: "1000"
79+
RootDirectory:
80+
Path: "/lambda"
81+
CreationInfo:
82+
OwnerGid: "1000"
83+
OwnerUid: "1000"
84+
Permissions: "755"
85+
86+
87+
2388
MyApi:
2489
Type: AWS::Serverless::Api
2590
DependsOn: MyApiCWLRoleArn
@@ -108,18 +173,35 @@ Resources:
108173

109174
GetProductByIdFunction:
110175
Type: AWS::Serverless::Function
176+
DependsOn:
177+
- MountTargetA
178+
- MountTargetB
179+
111180
Properties:
112181
PackageType: Image
113-
ImageUri: !Sub ${AWS::AccountId}.dkr.ecr.eu-central-1.amazonaws.com/aws-spring-boot-3.2-java21-with-crac-custom-docker-image:v1
182+
ImageUri: !Sub ${AWS::AccountId}.dkr.ecr.eu-central-1.amazonaws.com/aws-spring-boot-3.2-java21-crac-custom-docker-image:v1
114183
ImageConfig:
115184
Command: ["org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest"]
116185
Environment:
117186
Variables:
187+
JAVA_TOOL_OPTIONS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Dspring.context.checkpoint=onRefresh -XX:CRaCCheckpointTo=/mnt/msg/crac"
118188
SPRING_CLOUD_FUNCTION_DEFINITION: getProductByIdHandler
119189
FunctionName: GetProductByIdWithSpringBootJava21DockerImageWithCRaC
120190
Policies:
191+
- EFSWriteAccessPolicy:
192+
FileSystem: !Ref EfsFileSystem
193+
AccessPoint: !Ref AccessPoint
121194
- DynamoDBReadPolicy:
122195
TableName: !Ref ProductsTable
196+
VpcConfig:
197+
SecurityGroupIds:
198+
- !Ref EfsLambdaSecurityGroup
199+
SubnetIds:
200+
- !Ref EfsLambdaSubnetA
201+
- !Ref EfsLambdaSubnetB
202+
FileSystemConfigs:
203+
- Arn: !GetAtt AccessPoint.Arn
204+
LocalMountPath: /mnt/msg
123205
Events:
124206
GetRequestById:
125207
Type: Api
@@ -144,6 +226,7 @@ Resources:
144226
Command: ["org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest"]
145227
Environment:
146228
Variables:
229+
JAVA_TOOL_OPTIONS: "-XX:+TieredCompilation -XX:TieredStopAtLevel=1"
147230
SPRING_CLOUD_FUNCTION_DEFINITION: createProductHandler
148231
FunctionName: PutProductWithSpringBoot32Java21DockerImageWithCRaC
149232
Policies:

0 commit comments

Comments
 (0)