diff --git a/examples/complete/README.md b/examples/complete/README.md index dafc546..c8aae23 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -49,7 +49,7 @@ You can find your API Gateway Endpoint URL in the output values displayed after Build your application with the `sam build` command. ```bash -zeroae.gate$ sam build +zeroae.gate$ sam build ``` The SAM CLI installs dependencies defined in `gate-app/build.gradle`, creates a deployment package, and saves it in the `.aws-sam/build` folder. diff --git a/examples/complete/gate-app/build.gradle b/examples/complete/gate-app/build.gradle index 553bc27..b296bb7 100644 --- a/examples/complete/gate-app/build.gradle +++ b/examples/complete/gate-app/build.gradle @@ -47,9 +47,8 @@ task packagegapp() { task gatecloudUnpack(type: Copy) { def zipFile = file("application.zip") - def outputDir = gateApplicationDir from zipTree(zipFile) - into outputDir + into gateApplicationDir } sourceSets.main.output.dir gateCloudDir, builtBy: gatecloudUnpack diff --git a/examples/complete/template.yaml b/examples/complete/template.yaml index 90efe80..918bc67 100644 --- a/examples/complete/template.yaml +++ b/examples/complete/template.yaml @@ -15,15 +15,33 @@ Globals: Timeout: 120 Resources: + ZAERuntimeWrapper: + Type: AWS::Serverless::LayerVersion + Metadata: + BuildMethod: makefile + Properties: + Description: ZeroAE's Runtime Wrapper + ContentUri: ../../runtime-wrapper + LicenseInfo: "Apache-2.0" + RetentionPolicy: Delete + LambdaGateApp: Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction Properties: CodeUri: gate-app Handler: co.zeroae.gate.App::handleRequest Runtime: java8.al2 - MemorySize: 768 + MemorySize: 512 + Layers: + - !Ref ZAERuntimeWrapper Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object Variables: + AWS_LAMBDA_EXEC_WRAPPER: /opt/bin/wrapper.sh + AWS_LAMBDA_EXEC_WRAPPER_EXCLUDE_ARGS: >- + -XX:+UseSerialGC + JAVA_TOOL_OPTIONS: >- + -XX:+PrintGC + -XX:+PrintGCDetails GATE_APP_NAME: application GATE_APP_COST_PER_REQUEST: 1 GATE_APP_DAILY_QUOTA: 10000 diff --git a/runtime-wrapper/Makefile b/runtime-wrapper/Makefile new file mode 100644 index 0000000..c18b10f --- /dev/null +++ b/runtime-wrapper/Makefile @@ -0,0 +1,3 @@ +build-%: + mkdir -p "$(ARTIFACTS_DIR)/bin" + cp wrapper.sh "$(ARTIFACTS_DIR)/bin" \ No newline at end of file diff --git a/runtime-wrapper/wrapper.sh b/runtime-wrapper/wrapper.sh new file mode 100755 index 0000000..9804af6 --- /dev/null +++ b/runtime-wrapper/wrapper.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# the path to the interpreter and all of the originally intended arguments +args=("$@") + +# remove any argument that matches AWS_LAMBDA_EXEC_WRAPPER_EXCLUDE_ARGS +for index in "${!args[@]}"; do + if [[ ${args[$index]} == *$AWS_LAMBDA_EXEC_WRAPPER_EXCLUDE_ARGS* ]]; then + unset args[$index] + fi +done + +# insert the extra options +# args=("${args[@]:0:$#-1}" "${extra_args[@]}" "${args[@]: -1}") + +# start the runtime with the extra options +exec "${args[@]}" \ No newline at end of file diff --git a/template.yaml b/template.yaml index 6a3dc86..ce32560 100644 --- a/template.yaml +++ b/template.yaml @@ -8,6 +8,17 @@ Parameters: Description: The Layer version (SNAPSHOT, 1.0.0, etc...) Resources: + ZAERuntimeWrapper: + Type: AWS::Serverless::LayerVersion + Metadata: + BuildMethod: makefile + Properties: + LayerName: zae-lambda-runtime-wrapper + Description: ZeroAE's Runtime Wrapper + ContentUri: runtime-wrapper + LicenseInfo: "Apache-2.0" + RetentionPolicy: Retain + ZAEGateLambdaLayer: Type: AWS::Serverless::LayerVersion Metadata: