Skip to content
This repository was archived by the owner on Jul 20, 2024. It is now read-only.

Commit 3160b23

Browse files
author
Pete
authored
Merge pull request #6 from seattleagainstslavery/feature/add_support_for_multiple_layers_and_functions
Feature/add support for multiple layers and functions
2 parents f80396e + 2991eae commit 3160b23

File tree

3 files changed

+68
-35
lines changed

3 files changed

+68
-35
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM python:3.8
1+
FROM python:3.7
22

33
RUN apt-get update
44
RUN apt-get install -y jq zip
55
RUN pip install awscli
66

77
ADD entrypoint.sh /entrypoint.sh
88
RUN chmod +x /entrypoint.sh
9-
ENTRYPOINT ["/entrypoint.sh"]
9+
ENTRYPOINT ["/entrypoint.sh"]

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: AWS Lambda Zip Deploy - Python
22
author: Qubitro
33
description: Zip deploy to AWS Lambda with requirements in a separate layer.
44
inputs:
5+
aws_region:
6+
description: the AWS region where your lambdas are located
7+
required: true
58
requirements_txt:
69
description: the name/path to the requirements.txt file
710
required: true
@@ -32,6 +35,7 @@ runs:
3235
using: 'docker'
3336
image: 'Dockerfile'
3437
args:
38+
- ${{ inputs.aws_region }}
3539
- ${{ inputs.requirements_txt }}
3640
- ${{ inputs.lambda_function_names }}
3741
- ${{ inputs.pip_layer_arn }}

entrypoint.sh

Lines changed: 62 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,99 @@ configure_aws_credentials(){
44
aws configure set aws_access_key_id "${INPUT_AWS_ACCESS_KEY_ID}"
55
aws configure set aws_secret_access_key "${INPUT_AWS_SECRET_ACCESS_KEY}"
66
aws configure set default.region "${INPUT_AWS_REGION}"
7+
echo "REGION SET AS: ${INPUT_AWS_REGION}"
78
}
89

9-
install_zip_dependencies(){
10+
publish_pip_layer(){
11+
ALL_LAYERS_ARN_VERSION=()
1012
echo "Installing and zipping dependencies..."
1113
mkdir python
1214
pip install --target=python -r "${INPUT_REQUIREMENTS_TXT}"
1315
zip -r dependencies.zip ./python
14-
}
15-
16-
publish_dependencies_as_layer(){
1716
echo "Publishing dependencies as a layer..."
1817
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_PIP_LAYER_ARN}" --zip-file fileb://dependencies.zip)
1918
PIP_LAYER_VERSION=$(jq '.Version' <<< "$result")
19+
ALL_LAYERS_ARN_VERSION+="${INPUT_PIP_LAYER_ARN}:${PIP_LAYER_VERSION}"
2020
rm -rf python
2121
rm dependencies.zip
2222
}
2323

2424
publish_custom_layers(){
25-
echo "Publishing custom layer 1"
26-
cd "${INPUT_CUSTOM_LAYER_1_PATH}"
27-
zip -r custom_layer_1.zip .
28-
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_CUSTOM_LAYER_1_ARN}" --zip-file fileb://custom_layer_1.zip)
29-
CUSTOM_LAYER_1_VERSION=$(jq '.Version' <<< "$result")
30-
cd ..
25+
if [ -z ${INPUT_CUSTOM_LAYER_1_PATH} ]; then
26+
echo "custom_layer_1_path is not set"
27+
else
28+
echo "Publishing custom layer 1"
29+
mkdir python
30+
cp -r ${INPUT_CUSTOM_LAYER_1_PATH} python
31+
zip -r custom_layer_1.zip ./python
32+
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_CUSTOM_LAYER_1_ARN}" --zip-file fileb://custom_layer_1.zip)
33+
CUSTOM_LAYER_1_VERSION=$(jq '.Version' <<< "$result")
34+
ALL_LAYERS_ARN_VERSION+=" ${INPUT_CUSTOM_LAYER_1_ARN}:${CUSTOM_LAYER_1_VERSION}"
35+
rm -rf python
36+
rm custom_layer_1.zip
37+
fi
3138

32-
echo "Publishing custom layer 2"
33-
cd "${INPUT_CUSTOM_LAYER_2_PATH}"
34-
zip -r custom_layer_2.zip .
35-
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_CUSTOM_LAYER_2_ARN}" --zip-file fileb://custom_layer_2.zip)
36-
CUSTOM_LAYER_2_VERSION=$(jq '.Version' <<< "$result")
37-
cd ..
39+
if [ -z ${INPUT_CUSTOM_LAYER_2_PATH} ]; then
40+
echo "custom_layer_2_path is not set"
41+
else
42+
echo "Publishing custom layer 2"
43+
mkdir python
44+
cp -r ${INPUT_CUSTOM_LAYER_2_PATH} python
45+
zip -r custom_layer_2.zip ./python
46+
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_CUSTOM_LAYER_2_ARN}" --zip-file fileb://custom_layer_2.zip)
47+
CUSTOM_LAYER_2_VERSION=$(jq '.Version' <<< "$result")
48+
ALL_LAYERS_ARN_VERSION+=" ${INPUT_CUSTOM_LAYER_2_ARN}:${CUSTOM_LAYER_2_VERSION}"
49+
rm -rf python
50+
rm custom_layer_2.zip
51+
fi
3852

39-
echo "Publishing custom layer 3"
40-
cd "${INPUT_CUSTOM_LAYER_3_PATH}"
41-
zip -r custom_layer_3.zip .
42-
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_CUSTOM_LAYER_3_ARN}" --zip-file fileb://custom_layer_3.zip)
43-
CUSTOM_LAYER_3_VERSION=$(jq '.Version' <<< "$result")
44-
cd ..
53+
if [ -z ${INPUT_CUSTOM_LAYER_3_PATH} ]; then
54+
echo "custom_layer_3_path is not set"
55+
else
56+
echo "Publishing custom layer 3"
57+
mkdir python
58+
cp -r ${INPUT_CUSTOM_LAYER_3_PATH} python
59+
zip -r custom_layer_3.zip ./python
60+
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_CUSTOM_LAYER_3_ARN}" --zip-file fileb://custom_layer_3.zip)
61+
CUSTOM_LAYER_3_VERSION=$(jq '.Version' <<< "$result")
62+
ALL_LAYERS_ARN_VERSION+=" ${INPUT_CUSTOM_LAYER_3_ARN}:${CUSTOM_LAYER_3_VERSION}"
63+
rm -rf python
64+
rm custom_layer_3.zip
65+
fi
4566

46-
echo "Publishing custom layer 4"
47-
cd "${INPUT_CUSTOM_LAYER_4_PATH}"
48-
zip -r custom_layer_4.zip .
49-
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_CUSTOM_LAYER_4_ARN}" --zip-file fileb://custom_layer_4.zip)
50-
CUSTOM_LAYER_4_VERSION=$(jq '.Version' <<< "$result")
51-
cd ..
67+
if [ -z ${INPUT_CUSTOM_LAYER_4_PATH} ]; then
68+
echo "custom_layer_4_path is not set"
69+
else
70+
echo "Publishing custom layer 4"
71+
mkdir python
72+
cp -r ${INPUT_CUSTOM_LAYER_4_PATH} python
73+
zip -r custom_layer_4.zip ./python
74+
local result=$(aws lambda publish-layer-version --layer-name "${INPUT_CUSTOM_LAYER_4_ARN}" --zip-file fileb://custom_layer_4.zip)
75+
CUSTOM_LAYER_4_VERSION=$(jq '.Version' <<< "$result")
76+
ALL_LAYERS_ARN_VERSION+=" ${INPUT_CUSTOM_LAYER_4_ARN}:${CUSTOM_LAYER_4_VERSION}"
77+
rm -rf python
78+
rm custom_layer_4.zip
79+
fi
5280
}
5381

5482
publish_function(){
5583
echo "Deploying the code for ${1}"
5684
cd "${1}"
57-
zip -r "${1}".zip .
58-
aws lambda update-function-code --function-name "${1}" --zip-file fileb://"${1}".zip
85+
zip -r code.zip .
86+
aws lambda update-function-code --function-name "${1}" --zip-file fileb://code.zip
87+
rm code.zip
5988
cd ..
6089
}
6190

6291
update_function_layers(){
6392
echo "Adding pip layer and custom layers to ${1}"
64-
aws lambda update-function-configuration --function-name "${1}" --layers "${INPUT_PIP_LAYER_ARN}:${PIP_LAYER_VERSION}" "${INPUT_CUSTOM_LAYER_1_ARN}:${CUSTOM_LAYER_1_VERSION}" "${INPUT_CUSTOM_LAYER_2_ARN}:${CUSTOM_LAYER_2_VERSION}" "${INPUT_CUSTOM_LAYER_3_ARN}:${CUSTOM_LAYER_3_VERSION}" "${INPUT_CUSTOM_LAYER_4_ARN}:${CUSTOM_LAYER_4_VERSION}"
93+
echo ${ALL_LAYERS_ARN_VERSION[@]}
94+
aws lambda update-function-configuration --function-name "${1}" --layers ${ALL_LAYERS_ARN_VERSION[@]}
6595
}
6696

6797
deploy_lambda_function(){
6898
configure_aws_credentials
69-
install_zip_dependencies
70-
publish_dependencies_as_layer
99+
publish_pip_layer
71100
publish_custom_layers
72101

73102
functionNames=(${INPUT_LAMBDA_FUNCTION_NAMES//,/ })

0 commit comments

Comments
 (0)