-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathawscli-lambda-package_macos.sh
executable file
·59 lines (41 loc) · 1.76 KB
/
awscli-lambda-package_macos.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
52
53
54
55
56
57
58
59
# The script will fail if any of the commands fail
set -e
# Automatically detects python version (only works for python3.x)
export PYTHON_VERSION=`python3 -c 'import sys; version=sys.version_info[:3]; print("{0}.{1}".format(*version))'`
# Temporary directory for the virtual environment
export VIRTUAL_ENV_DIR="awscli-virtualenv"
# Temporary directory for AWS CLI and its dependencies
export LAMBDA_LAYER_DIR="awscli-lambda-layer"
# The zip file that will contain the layer
export ZIP_FILE_NAME="awscli-lambda-layer.zip"
# Creates a directory for virtual environment
mkdir ${VIRTUAL_ENV_DIR}
# Initializes a virtual environment in the virtual environment directory
virtualenv -p python3 ${VIRTUAL_ENV_DIR}
# Changes current dir to the virtual env directory
cd ${VIRTUAL_ENV_DIR}/bin/
# Activate virtual environment
source activate
# Installs AWS CLI and its dependencies
pip install awscli
# Modifies the first line of aws file to #!/var/lang/bin/python (path to Python3 in Lambda)
# if this command fails, you can manually edit the first line in the "aws" file in a text editor
sed -i '' "1s/.*/\#\!\/var\/lang\/bin\/python/" aws
# Deactivates the virtual env
deactivate
# Changes current directory back to where it started
cd ../..
# Creates a temporary directory to store AWS CLI and its dependencies
mkdir ${LAMBDA_LAYER_DIR}
# Changes the current directory into the temporary directory
cd ${LAMBDA_LAYER_DIR}
# Copies aws and its dependencies to the temp directory
cp ../${VIRTUAL_ENV_DIR}/bin/aws .
cp -r ../${VIRTUAL_ENV_DIR}/lib/python${PYTHON_VERSION}/site-packages/* .
# Zips the contents of the temporary directory
zip -r ../${ZIP_FILE_NAME} *
# Goes back to where it started
cd ..
# Removes virtual env and temp directories
rm -r ${VIRTUAL_ENV_DIR}
rm -r ${LAMBDA_LAYER_DIR}