1+ #! /bin/bash
2+
3+ configure_aws_credentials (){
4+ aws configure set aws_access_key_id " ${INPUT_AWS_ACCESS_KEY_ID} "
5+ aws configure set aws_secret_access_key " ${INPUT_AWS_SECRET_ACCESS_KEY} "
6+ aws configure set default.region " ${INPUT_LAMBDA_REGION} "
7+ }
8+
9+ install_zip_dependencies (){
10+ echo " Installing and zipping dependencies..."
11+ mkdir python
12+ pip install --target=python -r " ${INPUT_REQUIREMENTS_TXT} "
13+ zip -r dependencies.zip ./python
14+ }
15+
16+ publish_dependencies_as_layer (){
17+ echo " Publishing dependencies as a layer..."
18+ local result=$( aws lambda publish-layer-version --layer-name " ${INPUT_LAMBDA_LAYER_ARN} " --zip-file fileb://dependencies.zip)
19+ LAYER_VERSION=$( jq ' .Version' <<< " $result" )
20+ rm -rf python
21+ rm dependencies.zip
22+ }
23+
24+ publish_function_code (){
25+ echo " Deploying the code itself..."
26+ zip -r code.zip . -x \* .git\*
27+ aws lambda update-function-code --function-name " ${INPUT_LAMBDA_FUNCTION_NAME} " --zip-file fileb://code.zip
28+ }
29+
30+ update_function_layers (){
31+ echo " Using the layer in the function..."
32+ aws lambda update-function-configuration --function-name " ${INPUT_LAMBDA_FUNCTION_NAME} " --layers " ${INPUT_LAMBDA_LAYER_ARN} :${LAYER_VERSION} "
33+ }
34+
35+ deploy_lambda_function (){
36+ configure_aws_credentials
37+ install_zip_dependencies
38+ publish_dependencies_as_layer
39+ publish_function_code
40+ update_function_layers
41+ }
42+
43+ deploy_lambda_function
44+ echo " Each step completed, check the logs if any error occured."
0 commit comments