-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathpublish-layers.sh
executable file
·117 lines (100 loc) · 3.85 KB
/
publish-layers.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/bin/bash -e
PY27_DIST=dist/python27.zip
PY3X_DIST=dist/python3x.zip
REGIONS=(
ap-northeast-1
ap-northeast-2
ap-south-1
ap-southeast-1
ap-southeast-2
ca-central-1
eu-central-1
eu-west-1
eu-west-2
eu-west-3
#sa-east-1
us-east-1
us-east-2
us-west-1
us-west-2
)
rm -rf dist python
mkdir -p dist
function usage {
echo "./publish-layers.sh [python2.7|python3.x]"
}
case "$1" in
"python2.7")
echo "Building iopipe layer for python2.7"
pip install -qU iopipe -t python/lib/python2.7/site-packages
find python -name '*.pyc' -exec rm -f {} +
zip -rq $PY27_DIST python
rm -rf python
echo "Build complete: ${PY27_DIST}"
py27_hash=$(git rev-parse HEAD)
py27_s3key="iopipe-python2.7/${py27_hash}.zip"
for region in "${REGIONS[@]}"; do
bucket_name="iopipe-layers-${region}"
echo "Uploading ${PY27_DIST} to s3://${bucket_name}/${py27_s3key}"
aws --region $region s3 cp $PY27_DIST "s3://${bucket_name}/${py27_s3key}"
echo "Publishing python2.7 layer to ${region}"
py27_version=$(aws lambda publish-layer-version \
--layer-name IOpipePython27 \
--content "S3Bucket=${bucket_name},S3Key=${py27_s3key}" \
--description "IOpipe Layer for Python 2.7" \
--compatible-runtimes python2.7 \
--license-info "Apache 2.0" \
--region $region \
--output text \
--query Version)
echo "Published python2.7 layer version ${py27_version} to ${region}"
echo "Setting public permissions for python2.7 layer version ${py27_version} in ${region}"
aws lambda add-layer-version-permission \
--layer-name IOpipePython27 \
--version-number $py27_version \
--statement-id public \
--action lambda:GetLayerVersion \
--principal "*" \
--region $region
echo "Public permissions set for python2.7 layer version ${py27_version} in region ${region}"
done
;;
"python3.x")
echo "Building iopipe Layer for python3.x"
pip install -qU iopipe -t python
find python -name '__pycache__' -exec rm -fr {} +
zip -rq $PY3X_DIST python
rm -rf python
echo "Build complete: ${PY3X_DIST}" \
py3x_hash=$(git rev-parse HEAD)
py3x_s3key="iopipe-python3.x/${py3x_hash}.zip"
for region in "${REGIONS[@]}"; do
bucket_name="iopipe-layers-${region}"
echo "Uploading ${PY3X_DIST} to s3://${bucket_name}/${py3x_s3key}"
aws --region $region s3 cp $PY3X_DIST "s3://${bucket_name}/${py3x_s3key}"
echo "Publishing python3.x layer to ${region}"
py3x_version=$(aws lambda publish-layer-version \
--layer-name IOpipePython \
--content "S3Bucket=${bucket_name},S3Key=${py3x_s3key}" \
--description "IOpipe Layer for Python 3.6+" \
--compatible-runtimes python3.6 python3.7 \
--license-info "Apache 2.0" \
--region $region \
--output text \
--query Version)
echo "published python3.x layer version ${py3x_version} to ${region}"
echo "Setting public permissions for python3.x layer version ${py3x_version} in ${region}"
aws lambda add-layer-version-permission \
--layer-name IOpipePython \
--version-number $py3x_version \
--statement-id public \
--action lambda:GetLayerVersion \
--principal "*" \
--region $region
echo "Public permissions set for python3.x Layer version ${py3x_version} in region ${region}"
done
;;
*)
usage
;;
esac