From f7a5245112e1d205a587a66f637ea8f6795bcaa9 Mon Sep 17 00:00:00 2001 From: Pixette Date: Sun, 21 Nov 2021 09:17:02 +0100 Subject: [PATCH 1/6] add public layer --- action.yml | 3 +++ entrypoint.sh | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/action.yml b/action.yml index 3ec3ec5..e81b2d1 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,8 @@ inputs: description: the path to the code for custom layer 4 custom_layer_4_arn: description: the ARN for custom layer 4 + public_layer_1_arn: + description: the ARN for public layer 4 lambda_function_names: description: The Lambda function names (comma-separated if you have multiple). Check the AWS docs/readme for examples. required: true @@ -47,6 +49,7 @@ runs: - ${{ inputs.custom_layer_3_arn }} - ${{ inputs.custom_layer_4_path }} - ${{ inputs.custom_layer_4_arn }} + - ${{ inputs.public_layer_1_arn }} branding: icon: 'cloud-lightning' color: 'white' diff --git a/entrypoint.sh b/entrypoint.sh index 49fab3a..e194802 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -107,6 +107,15 @@ publish_custom_layers(){ fi } +publish_public_layers(){ + if [ -z ${INPUT_PUBLIC_LAYER_1_ARN} ]; then + echo "public_layer_1_arn is not set" + else + echo "Publishing public layer 1" + ALL_LAYERS_ARN_VERSION+=" ${INPUT_PUBLIC_LAYER_1_ARN}" + fi +} + publish_function(){ echo "Deploying the code for ${1}" cd "${1}" @@ -126,6 +135,7 @@ deploy_lambda_function(){ configure_aws_credentials publish_pip_layer publish_custom_layers + publish_public_layers functionNames=(${INPUT_LAMBDA_FUNCTION_NAMES//,/ }) for name in ${functionNames[@]}; do From e89f624102f0676956f1312484ef249ad933340b Mon Sep 17 00:00:00 2001 From: Pixette Date: Sun, 21 Nov 2021 12:56:57 +0100 Subject: [PATCH 2/6] final public layer --- README.md | 8 ++++++++ action.yml | 9 +++++++++ entrypoint.sh | 21 +++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/README.md b/README.md index 4961190..03884b7 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,14 @@ Storing credentials as a Github secret is strongly recommended. Same as above if you need more layers. - `custom_layer_4_arn` Same as above if you need more layers. +- `public_layer_1_arn` + The ARN of an external public Lambda layer in case you need one (e.g. https://github.com/keithrozario/Klayers). +- `public_layer_2_arn` + Same as above if you need more layers. +- `public_layer_3_arn` + Same as above if you need more layers. +- `public_layer_4_arn` + Same as above if you need more layers. - `lambda_function_names` The Lambda function names comma separated. - `aws_region` diff --git a/action.yml b/action.yml index e81b2d1..9a98765 100644 --- a/action.yml +++ b/action.yml @@ -29,6 +29,12 @@ inputs: custom_layer_4_arn: description: the ARN for custom layer 4 public_layer_1_arn: + description: the ARN for public layer 1 + public_layer_2_arn: + description: the ARN for public layer 2 + public_layer_3_arn: + description: the ARN for public layer 3 + public_layer_4_arn: description: the ARN for public layer 4 lambda_function_names: description: The Lambda function names (comma-separated if you have multiple). Check the AWS docs/readme for examples. @@ -50,6 +56,9 @@ runs: - ${{ inputs.custom_layer_4_path }} - ${{ inputs.custom_layer_4_arn }} - ${{ inputs.public_layer_1_arn }} + - ${{ inputs.public_layer_2_arn }} + - ${{ inputs.public_layer_3_arn }} + - ${{ inputs.public_layer_4_arn }} branding: icon: 'cloud-lightning' color: 'white' diff --git a/entrypoint.sh b/entrypoint.sh index e194802..242ded5 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -114,6 +114,27 @@ publish_public_layers(){ echo "Publishing public layer 1" ALL_LAYERS_ARN_VERSION+=" ${INPUT_PUBLIC_LAYER_1_ARN}" fi + + if [ -z ${INPUT_PUBLIC_LAYER_2_ARN} ]; then + echo "public_layer_1_arn is not set" + else + echo "Publishing public layer 1" + ALL_LAYERS_ARN_VERSION+=" ${INPUT_PUBLIC_LAYER_2_ARN}" + fi + + if [ -z ${INPUT_PUBLIC_LAYER_3_ARN} ]; then + echo "public_layer_1_arn is not set" + else + echo "Publishing public layer 1" + ALL_LAYERS_ARN_VERSION+=" ${INPUT_PUBLIC_LAYER_3_ARN}" + fi + + if [ -z ${INPUT_PUBLIC_LAYER_4_ARN} ]; then + echo "public_layer_1_arn is not set" + else + echo "Publishing public layer 1" + ALL_LAYERS_ARN_VERSION+=" ${INPUT_PUBLIC_LAYER_4_ARN}" + fi } publish_function(){ From eccf5903bd048010878965e153d3890df9e101d8 Mon Sep 17 00:00:00 2001 From: Pixette Date: Sun, 21 Nov 2021 21:20:38 +0100 Subject: [PATCH 3/6] remove local path --- entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/entrypoint.sh b/entrypoint.sh index 242ded5..5488fbe 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -41,6 +41,7 @@ publish_custom_layers(){ ALL_LAYERS_ARN_VERSION+=" ${INPUT_CUSTOM_LAYER_1_ARN}:${CUSTOM_LAYER_1_VERSION}" rm -rf python rm custom_layer_1.zip + rm -rf ${INPUT_CUSTOM_LAYER_1_PATH} fi if [ -z ${INPUT_CUSTOM_LAYER_2_PATH} ]; then From 82cfe93a2e6314e688a0c03da54aa313c761ce77 Mon Sep 17 00:00:00 2001 From: Pixette Date: Sun, 21 Nov 2021 21:37:43 +0100 Subject: [PATCH 4/6] delete local fodler for custom layer --- entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/entrypoint.sh b/entrypoint.sh index 5488fbe..f80f819 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -63,6 +63,7 @@ publish_custom_layers(){ ALL_LAYERS_ARN_VERSION+=" ${INPUT_CUSTOM_LAYER_2_ARN}:${CUSTOM_LAYER_2_VERSION}" rm -rf python rm custom_layer_2.zip + rm -rf ${INPUT_CUSTOM_LAYER_2_PATH} fi if [ -z ${INPUT_CUSTOM_LAYER_3_PATH} ]; then @@ -84,6 +85,7 @@ publish_custom_layers(){ ALL_LAYERS_ARN_VERSION+=" ${INPUT_CUSTOM_LAYER_3_ARN}:${CUSTOM_LAYER_3_VERSION}" rm -rf python rm custom_layer_3.zip + rm -rf ${INPUT_CUSTOM_LAYER_3_PATH} fi if [ -z ${INPUT_CUSTOM_LAYER_4_PATH} ]; then @@ -105,6 +107,7 @@ publish_custom_layers(){ ALL_LAYERS_ARN_VERSION+=" ${INPUT_CUSTOM_LAYER_4_ARN}:${CUSTOM_LAYER_4_VERSION}" rm -rf python rm custom_layer_4.zip + rm -rf ${INPUT_CUSTOM_LAYER_4_PATH} fi } From 4fe903505bfbc70c8a348b47393391937712d425 Mon Sep 17 00:00:00 2001 From: Pixette Date: Sun, 21 Nov 2021 21:52:55 +0100 Subject: [PATCH 5/6] fix deploy --- entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index f80f819..3e6e2aa 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -143,11 +143,11 @@ publish_public_layers(){ publish_function(){ echo "Deploying the code for ${1}" - cd "${1}" + # cd "${1}" zip -r code.zip . aws lambda update-function-code --function-name "${1}" --zip-file fileb://code.zip rm code.zip - cd .. + # cd .. } update_function_layers(){ From 3f0ce701709c23211e46514938a497e35ed0d6d7 Mon Sep 17 00:00:00 2001 From: Pixette Date: Sun, 21 Nov 2021 21:57:04 +0100 Subject: [PATCH 6/6] simplify --- entrypoint.sh | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 3e6e2aa..e421486 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -141,14 +141,14 @@ publish_public_layers(){ fi } -publish_function(){ - echo "Deploying the code for ${1}" - # cd "${1}" - zip -r code.zip . - aws lambda update-function-code --function-name "${1}" --zip-file fileb://code.zip - rm code.zip - # cd .. -} +# publish_function(){ +# echo "Deploying the code for ${1}" +# # cd "${1}" +# zip -r code.zip . +# aws lambda update-function-code --function-name "${1}" --zip-file fileb://code.zip +# rm code.zip +# # cd .. +# } update_function_layers(){ echo "Adding pip layer and custom layers to ${1}" @@ -163,10 +163,14 @@ deploy_lambda_function(){ publish_public_layers functionNames=(${INPUT_LAMBDA_FUNCTION_NAMES//,/ }) + zip -r code.zip . for name in ${functionNames[@]}; do - publish_function $name + echo "Deploying the code for ${1}" + aws lambda update-function-code --function-name "${1}" --zip-file fileb://code.zip + # publish_function $name update_function_layers $name done + rm code.zip } deploy_lambda_function