-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_lambda_package.sh
51 lines (41 loc) · 1.48 KB
/
build_lambda_package.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
cd k8s/resources
# Declare variable for reuse in directory validations
PACKAGE="package"
# Create directory and install lambda function dependencies
if [ -d $PACKAGE ]
then
echo "The directory "$PACKAGE" already exists."
else
echo "============================================="
echo "Creating the directory "$PACKAGE"..."
mkdir $PACKAGE
echo "The directory "$PACKAGE" was created."
echo "============================================="
fi
# Declares the variable that locates the requirements with the project's dependencies.
FILE_REQUIREMENTS=../scripts/requirements.txt
# Checks if the lambda_requirements file exists
if [ -f $FILE_REQUIREMENTS ]
then
echo "============================================="
echo "Installing dependencies located in "$FILE_REQUIREMENTS""
pip install --target ./package -r $FILE_REQUIREMENTS
echo "Dependencies installed successfully."
echo "============================================="
fi
cd $PACKAGE
# Declares variable that locates the lambda function for reuse in code.
LAMBDA_FUNCTION=../../lambda-function/lambda_function.py
# Checks if the lambda_function.py file exists.
if [ -f $LAMBDA_FUNCTION ]
then
echo "============================================="
echo "Copying Handler function..."
cp $LAMBDA_FUNCTION .
echo "Compressing file lambda_function.zip"
zip -r9 ../lambda_function.zip . # Compress the package for deployment
echo "File zipped successfully!"
echo "============================================="
fi
cd ..