From da06dbbb316d91d1a7bd43380dbbae9b8d726934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Sodr=C3=A9?= Date: Thu, 11 Mar 2021 18:57:43 -0500 Subject: [PATCH 1/6] Add Runtime wrapper command. It allows the user to exclude any of the default arguments generated by AWS bootstrap program. --- examples/complete/README.md | 4 +++- examples/complete/gate-app/build.gradle | 12 ++++++++++-- examples/complete/template.yaml | 9 ++++++++- examples/complete/wrapper.sh | 16 ++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) create mode 100755 examples/complete/wrapper.sh diff --git a/examples/complete/README.md b/examples/complete/README.md index dafc546..e9873ae 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -31,6 +31,7 @@ To build and deploy your application for the first time, run the following in yo ```bash sam build +find .aws-sam -type f -name 'wrapper.sh' -exec chmod 755 {} \; sam deploy --guided ``` @@ -49,7 +50,8 @@ 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 +zeroae.gate$ find .aws-sam -type f -name 'wrapper.sh' -exec chmod 755 {} \; ``` 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..b8d446d 100644 --- a/examples/complete/gate-app/build.gradle +++ b/examples/complete/gate-app/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' } +ext.binDir = file("$buildDir/bin") ext.gateCloudDir = file("$buildDir/gatecloud") ext.gateApplicationDir = file("$gateCloudDir/application") @@ -45,11 +46,18 @@ task packagegapp() { } } +task copyBin(type: Copy) { + from "../wrapper.sh" + into binDir + + fileMode 0755 +} + 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 +sourceSets.main.output.dir binDir, builtBy: copyBin diff --git a/examples/complete/template.yaml b/examples/complete/template.yaml index 90efe80..89be8a4 100644 --- a/examples/complete/template.yaml +++ b/examples/complete/template.yaml @@ -21,9 +21,16 @@ Resources: CodeUri: gate-app Handler: co.zeroae.gate.App::handleRequest Runtime: java8.al2 - MemorySize: 768 + MemorySize: 512 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: /var/task/wrapper.sh + AWS_LAMBDA_EXEC_WRAPPER_EXCLUDE_ARGS: |- + -XX:+UseSerialGC + JAVA_TOOL_OPTIONS: |- + -XX:+PrintGC + -XX:+PrintGCDetails + -XX:+PrintFlagsFinal GATE_APP_NAME: application GATE_APP_COST_PER_REQUEST: 1 GATE_APP_DAILY_QUOTA: 10000 diff --git a/examples/complete/wrapper.sh b/examples/complete/wrapper.sh new file mode 100755 index 0000000..9804af6 --- /dev/null +++ b/examples/complete/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 From 2182a0ea44f760167edfc4311b990b8c956b4be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Sodr=C3=A9?= Date: Fri, 12 Mar 2021 15:44:44 -0500 Subject: [PATCH 2/6] Build a layer for the runtime-wrapper command. --- examples/complete/gate-app/build.gradle | 10 +--------- examples/complete/template.yaml | 19 +++++++++++++++---- runtime-wrapper/Makefile | 3 +++ .../complete => runtime-wrapper}/wrapper.sh | 0 template.yaml | 11 +++++++++++ 5 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 runtime-wrapper/Makefile rename {examples/complete => runtime-wrapper}/wrapper.sh (100%) diff --git a/examples/complete/gate-app/build.gradle b/examples/complete/gate-app/build.gradle index b8d446d..3fb63f8 100644 --- a/examples/complete/gate-app/build.gradle +++ b/examples/complete/gate-app/build.gradle @@ -46,18 +46,10 @@ task packagegapp() { } } -task copyBin(type: Copy) { - from "../wrapper.sh" - into binDir - - fileMode 0755 -} - task gatecloudUnpack(type: Copy) { def zipFile = file("application.zip") from zipTree(zipFile) into gateApplicationDir } -sourceSets.main.output.dir gateCloudDir, builtBy: gatecloudUnpack -sourceSets.main.output.dir binDir, builtBy: copyBin +sourceSets.main.output.dir gateCloudDir, builtBy: gatecloudUnpack \ No newline at end of file diff --git a/examples/complete/template.yaml b/examples/complete/template.yaml index 89be8a4..b7402bd 100644 --- a/examples/complete/template.yaml +++ b/examples/complete/template.yaml @@ -15,6 +15,16 @@ Globals: Timeout: 120 Resources: + ZAERuntimeWrapper: + Type: AWS::Serverless::LayerVersion + Metadata: + BuildMethod: makefile + Properties: + Description: ZeroAE's Runtime Wrapper + ContentUri: ../.. + 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: @@ -22,15 +32,16 @@ Resources: Handler: co.zeroae.gate.App::handleRequest Runtime: java8.al2 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: /var/task/wrapper.sh - AWS_LAMBDA_EXEC_WRAPPER_EXCLUDE_ARGS: |- + AWS_LAMBDA_EXEC_WRAPPER: /opt/bin/wrapper.sh + AWS_LAMBDA_EXEC_WRAPPER_EXCLUDE_ARGS: >- -XX:+UseSerialGC - JAVA_TOOL_OPTIONS: |- + JAVA_TOOL_OPTIONS: >- -XX:+PrintGC -XX:+PrintGCDetails - -XX:+PrintFlagsFinal 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..df7cf23 --- /dev/null +++ b/runtime-wrapper/Makefile @@ -0,0 +1,3 @@ +build-ZAERuntimeWrapper: + mkdir -p "$(ARTIFACTS_DIR)/bin" + cp runtime-wrapper/wrapper.sh "$(ARTIFACTS_DIR)/bin" \ No newline at end of file diff --git a/examples/complete/wrapper.sh b/runtime-wrapper/wrapper.sh similarity index 100% rename from examples/complete/wrapper.sh rename to runtime-wrapper/wrapper.sh 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: From 50afc34467bd481713f523fe4c97d8bf86626a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Sodr=C3=A9?= Date: Fri, 12 Mar 2021 17:13:32 -0500 Subject: [PATCH 3/6] Make runtime-wrapper self-contained. --- examples/complete/template.yaml | 2 +- runtime-wrapper/Makefile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/complete/template.yaml b/examples/complete/template.yaml index b7402bd..918bc67 100644 --- a/examples/complete/template.yaml +++ b/examples/complete/template.yaml @@ -21,7 +21,7 @@ Resources: BuildMethod: makefile Properties: Description: ZeroAE's Runtime Wrapper - ContentUri: ../.. + ContentUri: ../../runtime-wrapper LicenseInfo: "Apache-2.0" RetentionPolicy: Delete diff --git a/runtime-wrapper/Makefile b/runtime-wrapper/Makefile index df7cf23..c18b10f 100644 --- a/runtime-wrapper/Makefile +++ b/runtime-wrapper/Makefile @@ -1,3 +1,3 @@ -build-ZAERuntimeWrapper: +build-%: mkdir -p "$(ARTIFACTS_DIR)/bin" - cp runtime-wrapper/wrapper.sh "$(ARTIFACTS_DIR)/bin" \ No newline at end of file + cp wrapper.sh "$(ARTIFACTS_DIR)/bin" \ No newline at end of file From 88ccb4d35b88d100b84ee7301d51af8bc4481876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Sodr=C3=A9?= Date: Fri, 12 Mar 2021 17:59:01 -0500 Subject: [PATCH 4/6] Update examples/complete/README.md --- examples/complete/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/complete/README.md b/examples/complete/README.md index e9873ae..7aebbfb 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -31,7 +31,6 @@ To build and deploy your application for the first time, run the following in yo ```bash sam build -find .aws-sam -type f -name 'wrapper.sh' -exec chmod 755 {} \; sam deploy --guided ``` From aebc03eaa4d4d8b1520ceaafb839535fcc1af70a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Sodr=C3=A9?= Date: Fri, 12 Mar 2021 17:59:08 -0500 Subject: [PATCH 5/6] Update examples/complete/README.md --- examples/complete/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/examples/complete/README.md b/examples/complete/README.md index 7aebbfb..c8aae23 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -50,7 +50,6 @@ Build your application with the `sam build` command. ```bash zeroae.gate$ sam build -zeroae.gate$ find .aws-sam -type f -name 'wrapper.sh' -exec chmod 755 {} \; ``` The SAM CLI installs dependencies defined in `gate-app/build.gradle`, creates a deployment package, and saves it in the `.aws-sam/build` folder. From 46aac07370b5ed9f02b88a2bebbab31f27bbd05e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Sodr=C3=A9?= Date: Fri, 12 Mar 2021 17:59:13 -0500 Subject: [PATCH 6/6] Update examples/complete/gate-app/build.gradle --- examples/complete/gate-app/build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/complete/gate-app/build.gradle b/examples/complete/gate-app/build.gradle index 3fb63f8..b296bb7 100644 --- a/examples/complete/gate-app/build.gradle +++ b/examples/complete/gate-app/build.gradle @@ -2,7 +2,6 @@ plugins { id 'java' } -ext.binDir = file("$buildDir/bin") ext.gateCloudDir = file("$buildDir/gatecloud") ext.gateApplicationDir = file("$gateCloudDir/application") @@ -52,4 +51,4 @@ task gatecloudUnpack(type: Copy) { from zipTree(zipFile) into gateApplicationDir } -sourceSets.main.output.dir gateCloudDir, builtBy: gatecloudUnpack \ No newline at end of file +sourceSets.main.output.dir gateCloudDir, builtBy: gatecloudUnpack