From 59a7cee71775431df7f00a8847aaa5b8d8608a81 Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Wed, 11 Nov 2020 19:00:07 -0800 Subject: [PATCH 01/15] added support for s3 buckets --- entrypoint.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 56856b5..4e0d304 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,7 +15,12 @@ install_zip_dependencies(){ publish_dependencies_as_layer(){ echo "Publishing dependencies as a layer..." - local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip) + if [[ -z ${INPUT_S3_BUCKET} ]]; then + local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip) + else + aws s3 cp ./dependencies.zip "s3://${INPUT_S3_BUCKET}/" + local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content "S3Bucket=${INPUT_S3_BUCKET},S3Key=dependencies.zip" + fi LAYER_VERSION=$(jq '.Version' <<< "$result") rm -rf python rm dependencies.zip @@ -41,4 +46,4 @@ deploy_lambda_function(){ } deploy_lambda_function -echo "Each step completed, check the logs if any error occured." \ No newline at end of file +echo "Each step completed, check the logs if any error occured." From 30c653c1919882ba5972d7cb7938dadd65a78700 Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Wed, 11 Nov 2020 19:08:39 -0800 Subject: [PATCH 02/15] Update action.yml --- action.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 008dae2..8ce050e 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,10 @@ inputs: lambda_function_name: description: The Lambda function name. Check the AWS docs/readme for examples. required: true + s3_bucket: + description: s3 bucket to put deps in + required: true + default: '' runs: using: 'docker' image: 'Dockerfile' @@ -20,6 +24,7 @@ runs: - ${{ inputs.lambda_layer_arn }} - ${{ inputs.lambda_function_name }} - ${{ inputs.lambda_region }} + - ${{ inputs.s3_bucket }} branding: icon: 'cloud-lightning' - color: 'white' \ No newline at end of file + color: 'white' From 69b4fe6f059f5f5f1ee275060d06caa5c3ab7f0a Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Wed, 11 Nov 2020 19:14:12 -0800 Subject: [PATCH 03/15] Update entrypoint.sh --- entrypoint.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 4e0d304..28f48a8 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -16,8 +16,10 @@ install_zip_dependencies(){ publish_dependencies_as_layer(){ echo "Publishing dependencies as a layer..." if [[ -z ${INPUT_S3_BUCKET} ]]; then + echo "uploading zip directly" local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip) else + echo "uploading zip to s3" aws s3 cp ./dependencies.zip "s3://${INPUT_S3_BUCKET}/" local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content "S3Bucket=${INPUT_S3_BUCKET},S3Key=dependencies.zip" fi From 79ba96c3819fd6ac2fc13a6060e4d9f4286a7f53 Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Wed, 11 Nov 2020 19:17:38 -0800 Subject: [PATCH 04/15] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 8ce050e..8768b77 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: AWS Lambda Zip Deploy - Python -author: Qubitro +author: chadtolentino description: Zip deploy to AWS Lambda with requirements in a separate layer. inputs: requirements_txt: From 2d77579b64209beb5e1ab9e1f9d60cf1f64a8c6c Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Wed, 11 Nov 2020 19:26:20 -0800 Subject: [PATCH 05/15] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 8768b77..b683628 100644 --- a/action.yml +++ b/action.yml @@ -12,7 +12,7 @@ inputs: lambda_function_name: description: The Lambda function name. Check the AWS docs/readme for examples. required: true - s3_bucket: + s3_bucket: description: s3 bucket to put deps in required: true default: '' From d2fa393983696cbfa4c3630d67fc3c0b42c4349c Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Wed, 11 Nov 2020 19:27:23 -0800 Subject: [PATCH 06/15] Update entrypoint.sh --- entrypoint.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 28f48a8..58f8b48 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,14 +15,14 @@ install_zip_dependencies(){ publish_dependencies_as_layer(){ echo "Publishing dependencies as a layer..." - if [[ -z ${INPUT_S3_BUCKET} ]]; then - echo "uploading zip directly" - local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip) - else - echo "uploading zip to s3" - aws s3 cp ./dependencies.zip "s3://${INPUT_S3_BUCKET}/" - local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content "S3Bucket=${INPUT_S3_BUCKET},S3Key=dependencies.zip" - fi + #if [[ -z ${INPUT_S3_BUCKET} ]]; then + # echo "uploading zip directly" + # local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip) + #else + echo "uploading zip to s3" + aws s3 cp ./dependencies.zip "s3://${INPUT_S3_BUCKET}/" + local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content "S3Bucket=${INPUT_S3_BUCKET},S3Key=dependencies.zip" + #fi LAYER_VERSION=$(jq '.Version' <<< "$result") rm -rf python rm dependencies.zip From 3eee0e0cb27a6ef79f3a3f2f05192ceec19148fd Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Wed, 11 Nov 2020 19:33:57 -0800 Subject: [PATCH 07/15] Update action.yml --- action.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/action.yml b/action.yml index b683628..f1c13be 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,6 @@ inputs: required: true s3_bucket: description: s3 bucket to put deps in - required: true default: '' runs: using: 'docker' From bf1381f7316484e3af1de151ecf57b32c1617078 Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Wed, 11 Nov 2020 19:35:46 -0800 Subject: [PATCH 08/15] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f1c13be..e8fc1f4 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,7 @@ inputs: required: true s3_bucket: description: s3 bucket to put deps in - default: '' + required: false runs: using: 'docker' image: 'Dockerfile' From 16c1e5defb82c33f74b2b96a5df80b07d8a8406b Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Wed, 11 Nov 2020 19:41:26 -0800 Subject: [PATCH 09/15] Update entrypoint.sh fixed typo --- entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.sh b/entrypoint.sh index 58f8b48..af6e161 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -21,7 +21,7 @@ publish_dependencies_as_layer(){ #else echo "uploading zip to s3" aws s3 cp ./dependencies.zip "s3://${INPUT_S3_BUCKET}/" - local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content "S3Bucket=${INPUT_S3_BUCKET},S3Key=dependencies.zip" + local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content "S3Bucket=${INPUT_S3_BUCKET},S3Key=dependencies.zip") #fi LAYER_VERSION=$(jq '.Version' <<< "$result") rm -rf python From 9ed93ac1f4b05f5a1088ed6582bfff2c0dd54aaa Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Wed, 11 Nov 2020 19:47:37 -0800 Subject: [PATCH 10/15] Update entrypoint.sh --- entrypoint.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index af6e161..f779598 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -15,14 +15,14 @@ install_zip_dependencies(){ publish_dependencies_as_layer(){ echo "Publishing dependencies as a layer..." - #if [[ -z ${INPUT_S3_BUCKET} ]]; then - # echo "uploading zip directly" - # local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip) - #else - echo "uploading zip to s3" - aws s3 cp ./dependencies.zip "s3://${INPUT_S3_BUCKET}/" - local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content "S3Bucket=${INPUT_S3_BUCKET},S3Key=dependencies.zip") - #fi + if [[ -z ${INPUT_S3_BUCKET} ]]; then + echo "uploading zip directly" + local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip) + else + echo "uploading zip to s3" + aws s3 cp ./dependencies.zip "s3://${INPUT_S3_BUCKET}/" + local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content "S3Bucket=${INPUT_S3_BUCKET},S3Key=dependencies.zip") + fi LAYER_VERSION=$(jq '.Version' <<< "$result") rm -rf python rm dependencies.zip From d399be70d7003515cb3b3342ca79cdf1ab05f510 Mon Sep 17 00:00:00 2001 From: chadtolentino <74264167+chadtolentino@users.noreply.github.com> Date: Thu, 12 Nov 2020 16:20:50 -0800 Subject: [PATCH 11/15] Updated readme to reflect changes --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 70f7977..274cfa8 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ GitHub Action to make zip deployment to AWS Lambda with requirements in a separa This action automatically installs requirements, zips and deploys the code including the dependencies as a separate layer. #### Python 3.8 is supported +#### Also supports uploading dependecies greater than 50MB to layer ### Pre-requisites In order for the Action to have access to the code, you must use the `actions/checkout@master` job before it. @@ -32,6 +33,8 @@ Storing credentials as secret is stronly recommended. - Partial ARN - `123456789012:function:function-name` - `requirements_txt` The name/path for the `requirements.txt` file. Defaults to `requirements.txt`. +- `s3_bucket` + Name of S3 bucket to upload dependencies.zip to ### Example Workflow ```yaml From c67fcedfadd48881b16d2c76d61c6742d3d0530f Mon Sep 17 00:00:00 2001 From: Chad T <74264167+chadtolentino@users.noreply.github.com> Date: Fri, 12 Mar 2021 23:35:18 -0800 Subject: [PATCH 12/15] Update README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 274cfa8..cc977ff 100644 --- a/README.md +++ b/README.md @@ -7,13 +7,13 @@ GitHub Action to make zip deployment to AWS Lambda with requirements in a separa This action automatically installs requirements, zips and deploys the code including the dependencies as a separate layer. #### Python 3.8 is supported -#### Also supports uploading dependecies greater than 50MB to layer +#### Also supports uploading dependencies greater than 50MB to layer (via s3 buckets) ### Pre-requisites In order for the Action to have access to the code, you must use the `actions/checkout@master` job before it. ### Structure -- Lambda code should be `lambda_function.py`** unless you want to have a customized file name. +- Lambda code should be `lambda_function.py` unless you want to have a customized file name. - **Dependencies must be stored in a `requirements.txt`** ### Environment variables @@ -34,7 +34,7 @@ Storing credentials as secret is stronly recommended. - `requirements_txt` The name/path for the `requirements.txt` file. Defaults to `requirements.txt`. - `s3_bucket` - Name of S3 bucket to upload dependencies.zip to + Name of S3 bucket to upload dependencies.zip to (for dependencies over 50 MB) ### Example Workflow ```yaml From 280fc44d52c29de79423cd15bb9dfffda6ad85bd Mon Sep 17 00:00:00 2001 From: Chad T <74264167+chadtolentino@users.noreply.github.com> Date: Fri, 12 Mar 2021 23:36:29 -0800 Subject: [PATCH 13/15] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index e8fc1f4..3f7cc12 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: AWS Lambda Zip Deploy - Python -author: chadtolentino +author: quibitro description: Zip deploy to AWS Lambda with requirements in a separate layer. inputs: requirements_txt: From 75620ef2a20fd10198dabe53fc670e3d4ef43cd1 Mon Sep 17 00:00:00 2001 From: Chad T <74264167+chadtolentino@users.noreply.github.com> Date: Fri, 12 Mar 2021 23:37:08 -0800 Subject: [PATCH 14/15] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 3f7cc12..0a97b89 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: AWS Lambda Zip Deploy - Python -author: quibitro +author: qubitro description: Zip deploy to AWS Lambda with requirements in a separate layer. inputs: requirements_txt: From b0ae9e45e73b6199ba20b59a56e4038855c4635a Mon Sep 17 00:00:00 2001 From: Chad T <74264167+chadtolentino@users.noreply.github.com> Date: Fri, 12 Mar 2021 23:38:23 -0800 Subject: [PATCH 15/15] Update action.yml --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 0a97b89..b1a4f2d 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: AWS Lambda Zip Deploy - Python -author: qubitro +author: Qubitro description: Zip deploy to AWS Lambda with requirements in a separate layer. inputs: requirements_txt: