forked from huksley/serverless-java-spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayers-support.patch
More file actions
114 lines (103 loc) · 3.76 KB
/
layers-support.patch
File metadata and controls
114 lines (103 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
This patch introduces support for layers,
however sam cli does not support it well, so it is not available here.
Probably can be turned on later when using serverless framework for running locally.
diff --git b/build.gradle a/build.gradle
index 0dcc715..a50b21b 100644
--- b/build.gradle
+++ a/build.gradle
@@ -41,5 +41,22 @@ task buildZipFull(type: Zip) {
}
}
}
+
+task buildZipCode(type: Zip) {
+ baseName = "serverless-java-spring-boot-code"
+ from compileJava
+ from processResources
+}
+
+task buildLayerZip(type: Zip) {
+ baseName = "serverless-java-spring-boot-layer1"
+ into("java/lib") {
+ from(configurations.compileClasspath) {
+ exclude 'tomcat-embed-*'
+ }
+ }
+}
build.dependsOn buildZipFull
+build.dependsOn buildZipCode
+build.dependsOn buildLayerZip
diff --git b/deploy-to-aws a/deploy-to-aws
index 492b7c3..3f36579 100755
--- b/deploy-to-aws
+++ a/deploy-to-aws
@@ -22,9 +22,20 @@ function parse_yaml {
eval $(parse_yaml sam-template.yaml)
+#LAYER_PACKAGE=build/distributions/serverless-java-spring-boot-layer1.zip
+#LAYER_NAME=`basename $LAYER_PACKAGE`
+#
+#aws s3 cp $LAYER_PACKAGE s3://${S3_BUCKET}/$LAYER_NAME
+#aws lambda publish-layer-version --layer-name serverless-java-spring-boot-layer1 \
+# --content S3Bucket=${S3_BUCKET},S3Key=${LAYER_NAME} \
+# --compatible-runtimes java8
+#LAYER_ARN=`aws lambda list-layer-versions --layer-name serverless-java-spring-boot-layer1 --max-items 1 | jq ".LayerVersions[0].LayerVersionArn" -r`
+#echo "JAR layer ARN: ${LAYER_ARN}"
+
aws cloudformation package --template-file sam-template.yaml --s3-bucket ${S3_BUCKET} --s3-prefix java --output-template-file sam-package.yaml
PARAMS="SNSTopic=${SNS_TOPIC} SQSQueue=${SQS_QUEUE}"
+# CodeLayers=${LAYER_ARN}
aws cloudformation deploy --template-file sam-package.yaml --stack-name ServerlessSpringApi --parameter-overrides ${PARAMS} --capabilities CAPABILITY_IAM
diff --git b/sam-local a/sam-local
index 047b969..98d8748 100755
--- b/sam-local
+++ a/sam-local
@@ -1,4 +1,9 @@
#!/bin/bash
-sam local start-api --debug --skip-pull-image -s public -t sam-template.yaml -p 3000 -n sam-local-env.json
+LAYER_ARN=`aws lambda list-layer-versions --layer-name serverless-java-spring-boot-layer1 --max-items 1 | jq ".LayerVersions[0].LayerVersionArn" -r`
+echo "JAR layer ARN: ${LAYER_ARN}"
+
+PARAMS=ParameterKey=CodeLayers,ParameterValue=${LAYER_ARN}
+
+sam local start-api --debug --skip-pull-image -s public -t sam-template.yaml -p 3000 -n sam-local-env.json --parameter-overrides ${PARAMS}
diff --git b/sam-template.yaml a/sam-template.yaml
index 17a9b5f..6481466 100644
--- b/sam-template.yaml
+++ a/sam-template.yaml
@@ -14,6 +14,8 @@ Parameters:
Type: String
SQSQueue:
Type: String
+# CodeLayers:
+# Type: CommaDelimitedList
Resources:
ApiGatewayApi:
@@ -24,16 +26,27 @@ Resources:
Variables:
Stage:
Ref: Stage
+ MyServiceLayer:
+ Type: AWS::Serverless::LayerVersion
+ Properties:
+ LayerName: serverless-java-spring-boot-layer1
+ ContentUri: "build/distributions/serverless-java-spring-boot-layer1.zip"
+ CompatibleRuntimes:
+ - java8
+ RetentionPolicy: Retain
MyServiceFunction:
Type: AWS::Serverless::Function
FunctionName: "ServerlessSpringApi-MyServiceFunction"
Properties:
Handler: my.service.StreamLambdaHandler::handleRequest
Runtime: java8
- CodeUri: "build/distributions/serverless-java-spring-boot.zip"
+ CodeUri: "build/distributions/serverless-java-spring-boot-code.zip"
MemorySize: 2048
Policies: AWSLambdaBasicExecutionRole
Timeout: 30
+ Layers:
+# Ref: CodeLayers
+ - !Ref MyServiceLayer
Environment:
Variables:
# Specify here variables for deployment,