diff --git a/Dockerfile b/Dockerfile index 869eedd..fbd9c15 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.6 +FROM python:3.13 RUN apt-get update RUN apt-get install -y jq zip diff --git a/README.md b/README.md index 1cad90c..7f40666 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ Stored as secrets or env vars, doesn't matter. But also please don't put your AW - Partial ARN - `123456789012:function:my-function` - `requirements_txt` The name/path for the `requirements.txt` file. Defaults to `requirements.txt`. +- `use_s3` + Whether to upload the dependency layer zip to S3 (required if the zip exceeds 50MB) or not. (If not, it's uploaded directly to Lambda.) Defaults to `false`. +- `s3_bucket_name` + The S3 bucket name used if you are uploading the dependency layer to S3. ### Example workflow diff --git a/action.yml b/action.yml index f06de98..45af266 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,14 @@ inputs: lambda_function_name: description: The Lambda function name. Check the AWS docs/readme for examples. required: true + use_s3: + description: Whether to use S3 (true) or not (false) for the dependencies layer upload. + required: false + default: 'false' + s3_bucket_name: + description: The S3 bucket name for the dependencies layer upload. + required: false + default: no-bucket-name-here runs: using: 'docker' image: 'Dockerfile' diff --git a/entrypoint.sh b/entrypoint.sh index 0ffdfed..3532894 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,6 +1,20 @@ #!/bin/bash set -e +poll_command="aws lambda get-function --function-name ${INPUT_LAMBDA_FUNCTION_NAME} --query Configuration.[State,LastUpdateStatus]" + +wait_state(){ + echo "Waiting on function state update..." + until ${poll_command} | grep "Active" + do + sleep 1 + done + until ${poll_command} | grep "Successful" + do + sleep 1 + done +} + install_zip_dependencies(){ echo "Installing and zipping dependencies..." mkdir python @@ -9,8 +23,16 @@ 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 [ "$INPUT_USE_S3" = true ] + then + echo "Uploading dependencies to S3..." + aws s3 cp dependencies.zip s3://"${INPUT_S3_BUCKET_NAME}"/dependencies.zip + echo "Publishing dependencies from S3 as a layer..." + local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --content S3Bucket="${INPUT_S3_BUCKET_NAME}",S3Key=dependencies.zip) + else + echo "Publishing dependencies as a layer..." + local result=$(aws lambda publish-layer-version --layer-name "${INPUT_LAMBDA_LAYER_ARN}" --zip-file fileb://dependencies.zip) + fi LAYER_VERSION=$(jq '.Version' <<< "$result") rm -rf python rm dependencies.zip @@ -18,7 +40,7 @@ publish_dependencies_as_layer(){ publish_function_code(){ echo "Deploying the code itself..." - zip -r code.zip . -x \*.git\* + zip -r code.zip *.py -x \*.git\* aws lambda update-function-code --function-name "${INPUT_LAMBDA_FUNCTION_NAME}" --zip-file fileb://code.zip } @@ -31,6 +53,7 @@ deploy_lambda_function(){ install_zip_dependencies publish_dependencies_as_layer publish_function_code + wait_state update_function_layers }