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 3ec3ec5..9a98765 100644 --- a/action.yml +++ b/action.yml @@ -28,6 +28,14 @@ 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 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. required: true @@ -47,6 +55,10 @@ runs: - ${{ inputs.custom_layer_3_arn }} - ${{ 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 49fab3a..e421486 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 @@ -62,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 @@ -83,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 @@ -104,18 +107,49 @@ 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 } -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_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 + + 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(){ +# 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}" echo ${ALL_LAYERS_ARN_VERSION[@]} @@ -126,12 +160,17 @@ deploy_lambda_function(){ configure_aws_credentials publish_pip_layer publish_custom_layers + 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