Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions deploy-to-aws
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion sam-local
Original file line number Diff line number Diff line change
@@ -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}

15 changes: 14 additions & 1 deletion sam-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Parameters:
Type: String
SQSQueue:
Type: String
# CodeLayers:
# Type: CommaDelimitedList

Resources:
ApiGatewayApi:
Expand All @@ -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,
Expand Down