Skip to content
This repository was archived by the owner on Oct 21, 2019. It is now read-only.

Commit 363e1a2

Browse files
author
Darren Weber
committed
Use packaging and test scripts for the lambda layer
1 parent 1eb75d8 commit 363e1a2

16 files changed

+208
-11
lines changed

Makefile

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,27 @@ container-clean:
3737
# lambda layer build and package using /opt
3838

3939
LAYER_BUILD = ${BUILD}-layer
40-
LAYER_PACKAGE := amazonlinux-${TAG}-layer.zip
40+
LAYER_PACKAGE := amazonlinux-${TAG}-layer
4141

4242
lambda-layer-build:
4343
docker build -f Dockerfile -t ${LAYER_BUILD} --build-arg prefix=/opt .
4444

4545
lambda-layer-shell: lambda-layer-build container-clean
46-
docker run --name amazonlinux --volume $(shell pwd)/:/data --rm -it ${LAYER_BUILD} /bin/bash
46+
docker run --name amazonlinux --volume $(shell pwd)/:/data --rm -it ${LAYER_BUILD} /bin/bash
47+
48+
lambda-layer-test: lambda-layer-build
49+
docker run --volume $(shell pwd)/:/data --rm -it ${LAYER_BUILD} /bin/bash -c '/data/tests/test.sh'
4750

4851
lambda-layer-package: lambda-layer-build container-clean
49-
docker run --name amazonlinux -itd ${LAYER_BUILD} /bin/bash
50-
docker exec -it amazonlinux bash -c 'mkdir -p $${PREFIX}/python/lib/python${PY_VERSION}/site-packages'
51-
docker exec -it amazonlinux bash -c 'rsync -a /var/lang/lib/python${PY_VERSION}/site-packages/ $${PREFIX}/python/lib/python${PY_VERSION}/site-packages/'
52-
docker exec -it amazonlinux bash -c 'cd $${PREFIX} && zip -r9 --symlinks /tmp/package.zip python'
53-
docker exec -it amazonlinux bash -c 'cd $${PREFIX} && zip -r9 --symlinks /tmp/package.zip lib/*.so*'
54-
docker exec -it amazonlinux bash -c 'cd $${PREFIX} && zip -r9 --symlinks /tmp/package.zip lib64/*.so*'
55-
docker exec -it amazonlinux bash -c 'cd $${PREFIX} && zip -r9 --symlinks /tmp/package.zip bin'
56-
docker exec -it amazonlinux bash -c 'cd $${PREFIX} && zip -r9 /tmp/package.zip share'
57-
docker cp amazonlinux:/tmp/package.zip ${LAYER_PACKAGE}
52+
docker run --name amazonlinux \
53+
-e PREFIX=${PREFIX} \
54+
-e PY_VERSION=${PY_VERSION} \
55+
-e LAYER_PACKAGE=${LAYER_PACKAGE} \
56+
-itd ${LAYER_BUILD} /bin/bash
57+
docker cp package_lambda_layer.sh amazonlinux:/tmp/package_lambda_layer.sh
58+
docker exec -it amazonlinux bash -c '/tmp/package_lambda_layer.sh'
59+
mkdir -p ./packages
60+
docker cp amazonlinux:/tmp/${LAYER_PACKAGE}_libs.zip ./packages/
61+
docker cp amazonlinux:/tmp/${LAYER_PACKAGE}_python.zip ./packages/
5862
docker stop amazonlinux && docker rm amazonlinux
5963

package_lambda_layer.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
prefix="${PREFIX:-/opt}"
4+
5+
py_version="${PY_VERSION:-3.6}"
6+
7+
layer_package="${LAYER_PACKAGE:-layer_package}"
8+
9+
10+
# Note: excluding many paths in the python libs crashed the layer runtime
11+
# somehow, so the excludes are disabled for now.
12+
src=/var/lang/lib/python${py_version}/site-packages
13+
dst=${prefix}/python/lib/python${py_version}/site-packages
14+
find $src -type d -name '__pycache__' -exec rm -rf {} +
15+
mkdir -p ${dst}
16+
rsync -a $src/ ${dst}/
17+
#rsync -a \
18+
# --exclude 'boto3' \
19+
# --exclude 'botocore' \
20+
# --exclude 'aws_lambda_builders' \
21+
# --exclude 'awscli' \
22+
# --exclude 's3transfer' \
23+
# --exclude 'samtranslator' \
24+
# --exclude 'docker' \
25+
# --exclude 'samcli' \
26+
# --exclude 'wheel' \
27+
# --exclude 'share/doc/*' \
28+
# --exclude 'share/man/man1/*' \
29+
# --exclude 'share/man/man3/*' \
30+
# --exclude 'pipenv' \
31+
# $src/ ${dst}/
32+
33+
# package the binary 'libs' and the python packages into two layers,
34+
# to reduce the size of each package and allow flexibility in using
35+
# just the binaries or the binaries plus the python bindings.
36+
cd ${prefix}
37+
zip -r9 --symlinks /tmp/${layer_package}_python.zip python
38+
zip -r9 --symlinks /tmp/${layer_package}_libs.zip bin lib/*.so* lib64/*.so* share
39+

tests/data/cea.tif

265 KB
Binary file not shown.

tests/data/cea.txt

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Cyldindrical Equal Area
2+
-----------------------
3+
4+
Frank Warmerdam
5+
6+
7+
Created by reprojecting utm11-27.tif in pci_eg directory.
8+
9+
Geotiff_Information:
10+
Version: 1
11+
Key_Revision: 1.0
12+
Tagged_Information:
13+
ModelTiepointTag (2,3):
14+
0 0 0
15+
-28493.1668 4255884.54 0
16+
ModelPixelScaleTag (1,3):
17+
60.022137 60.022137 0
18+
End_Of_Tags.
19+
Keyed_Information:
20+
GTModelTypeGeoKey (Short,1): ModelTypeProjected
21+
GTRasterTypeGeoKey (Short,1): RasterPixelIsArea
22+
GTCitationGeoKey (Ascii,8): "unnamed"
23+
GeographicTypeGeoKey (Short,1): GCS_NAD27
24+
GeogCitationGeoKey (Ascii,6): "NAD27"
25+
GeogAngularUnitsGeoKey (Short,1): Angular_Degree
26+
ProjectedCSTypeGeoKey (Short,1): User-Defined
27+
ProjectionGeoKey (Short,1): User-Defined
28+
ProjCoordTransGeoKey (Short,1): CT_CylindricalEqualArea
29+
ProjLinearUnitsGeoKey (Short,1): Linear_Meter
30+
ProjStdParallel1GeoKey (Double,1): 33.75
31+
ProjNatOriginLongGeoKey (Double,1): -117.333333
32+
ProjFalseEastingGeoKey (Double,1): 0
33+
ProjFalseNorthingGeoKey (Double,1): 0
34+
End_Of_Keys.
35+
End_Of_Geotiff.
36+
37+
Projection Method: CT_CylindricalEqualArea
38+
ProjStdParallel1GeoKey: 33.750000 ( 33d45' 0.00"N)
39+
ProjNatOriginLongGeoKey: -117.333333 (117d20' 0.00"W)
40+
ProjFalseEastingGeoKey: 0.000000 m
41+
ProjFalseNorthingGeoKey: 0.000000 m
42+
GCS: 4267/NAD27
43+
Datum: 6267/North American Datum 1927
44+
Ellipsoid: 7008/Clarke 1866 (6378206.40,6356583.80)
45+
Prime Meridian: 8901/Greenwich (0.000000/ 0d 0' 0.00"E)
46+
Projection Linear Units: 9001/metre (1.000000m)
47+
48+
Corner Coordinates:
49+
Upper Left ( -28493.167, 4255884.544) (117d38'28.21"W, 33d54'13.08"N)
50+
Lower Left ( -28493.167, 4224973.143) (117d38'28.21"W, 33d37'30.66"N)
51+
Upper Right ( 2358.212, 4255884.544) (117d18'28.28"W, 33d54'13.08"N)
52+
Lower Right ( 2358.212, 4224973.143) (117d18'28.28"W, 33d37'30.66"N)
53+
Center ( -13067.478, 4240428.844) (117d28'28.24"W, 33d45'51.47"N)
54+
55+
From gdalinfo:
56+
57+
Driver: GTiff/GeoTIFF
58+
Size is 514, 515
59+
Coordinate System is:
60+
PROJCS["unnamed",
61+
GEOGCS["NAD27",
62+
DATUM["North_American_Datum_1927",
63+
SPHEROID["Clarke 1866",6378206.4,294.9786982138982,
64+
AUTHORITY["EPSG","7008"]],
65+
AUTHORITY["EPSG","6267"]],
66+
PRIMEM["Greenwich",0],
67+
UNIT["degree",0.0174532925199433],
68+
AUTHORITY["EPSG","4267"]],
69+
PROJECTION["Cylindrical_Equal_Area"],
70+
PARAMETER["standard_parallel_1",33.75],
71+
PARAMETER["central_meridian",-117.333333333333],
72+
PARAMETER["false_easting",0],
73+
PARAMETER["false_northing",0],
74+
UNIT["metre",1,
75+
AUTHORITY["EPSG","9001"]]]
76+
Origin = (-28493.166784,4255884.543802)
77+
Pixel Size = (60.02213698,-60.02213698)
78+
Corner Coordinates:
79+
Upper Left ( -28493.167, 4255884.544) (117d38'28.21"W, 33d54'13.08"N)
80+
Lower Left ( -28493.167, 4224973.143) (117d38'28.21"W, 33d37'30.66"N)
81+
Upper Right ( 2358.212, 4255884.544) (117d18'28.28"W, 33d54'13.08"N)
82+
Lower Right ( 2358.212, 4224973.143) (117d18'28.28"W, 33d37'30.66"N)
83+
Center ( -13067.478, 4240428.844) (117d28'28.24"W, 33d45'51.47"N)
84+
Band 1 Block=514x15 Type=Byte, ColorInterp=Gray

tests/data/raster_tmp.dbf

226 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)