Skip to content

Commit b1e7279

Browse files
committed
PDAL AWS Lambda layer creation
1 parent a53eb88 commit b1e7279

File tree

6 files changed

+240
-0
lines changed

6 files changed

+240
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lambda-deploy.zip
2+

Dockerfile

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
FROM lambci/lambda:build-python3.6 as builder
2+
3+
ARG http_proxy
4+
ARG CURL_VERSION=7.63.0
5+
ARG GDAL_VERSION=2.4.0
6+
ARG GEOS_VERSION=3.7.1
7+
ARG PROJ_VERSION=5.1.0
8+
ARG LASZIP_VERSION=3.2.9
9+
ARG GEOTIFF_VERSION=1.4.3
10+
ARG PDAL_VERSION=1.8.0
11+
ARG DESTDIR="/build"
12+
ARG PREFIX="/usr"
13+
14+
RUN \
15+
rpm --rebuilddb && \
16+
yum makecache fast && \
17+
yum install -y \
18+
automake16 \
19+
libpng-devel \
20+
nasm wget tar gcc zlib-devel gcc-c++ curl-devel zip libjpeg-devel rsync git ssh bzip2 automake \
21+
glib2-devel libtiff-devel pkg-config libcurl-devel; # required for pkg-config
22+
23+
RUN \
24+
wget https://github.com/Kitware/CMake/releases/download/v3.13.2/cmake-3.13.2.tar.gz; \
25+
tar -zxvf cmake-3.13.2.tar.gz; \
26+
cd cmake-3.13.2; \
27+
./bootstrap --prefix=/usr ;\
28+
make ;\
29+
make install DESTDIR=/
30+
31+
32+
RUN \
33+
wget https://github.com/LASzip/LASzip/releases/download/$LASZIP_VERSION/laszip-src-$LASZIP_VERSION.tar.gz; \
34+
tar -xzvf laszip-src-$LASZIP_VERSION.tar.gz; \
35+
cd laszip-src-$LASZIP_VERSION;\
36+
cmake -DCMAKE_BUILD_TYPE=Release \
37+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
38+
-DBUILD_SHARED_LIBS=ON \
39+
-DBUILD_STATIC_LIBS=OFF \
40+
-DCMAKE_INSTALL_LIBDIR=lib \
41+
; \
42+
make; make install; make install DESTDIR= ; cd ..; \
43+
rm -rf laszip-src-${LASZIP_VERSION} laszip-src-$LASZIP_VERSION.tar.gz;
44+
45+
RUN \
46+
wget http://download.osgeo.org/geos/geos-$GEOS_VERSION.tar.bz2; \
47+
tar xjf geos*bz2; \
48+
cd geos*; \
49+
./configure --prefix=$PREFIX CFLAGS="-O2 -Os"; \
50+
make; make install; make install DESTDIR= ;\
51+
cd ..; \
52+
rm -rf geos*;
53+
54+
RUN \
55+
wget http://download.osgeo.org/proj/proj-$PROJ_VERSION.tar.gz; \
56+
tar -zvxf proj-$PROJ_VERSION.tar.gz; \
57+
cd proj-$PROJ_VERSION; \
58+
./configure --prefix=$PREFIX; \
59+
make; make install; make install DESTDIR=; cd ..; \
60+
rm -rf proj-$PROJ_VERSION proj-$PROJ_VERSION.tar.gz
61+
62+
RUN \
63+
wget https://download.osgeo.org/geotiff/libgeotiff/libgeotiff-$GEOTIFF_VERSION.tar.gz; \
64+
tar -xzvf libgeotiff-$GEOTIFF_VERSION.tar.gz; \
65+
cd libgeotiff-$GEOTIFF_VERSION; \
66+
./configure \
67+
--prefix=$PREFIX --with-proj=/build/usr ;\
68+
make; make install; make install DESTDIR=; cd ..; \
69+
rm -rf libgeotiff-$GEOTIFF_VERSION.tar.gz libgeotiff-$GEOTIFF_VERSION;
70+
71+
# GDAL
72+
RUN \
73+
wget http://download.osgeo.org/gdal/$GDAL_VERSION/gdal-$GDAL_VERSION.tar.gz; \
74+
tar -xzvf gdal-$GDAL_VERSION.tar.gz; \
75+
cd gdal-$GDAL_VERSION; \
76+
./configure \
77+
--prefix=$PREFIX \
78+
--with-geotiff=$DESTDIR/usr \
79+
--with-tiff=/usr \
80+
--with-curl=yes \
81+
--without-python \
82+
--with-geos=$DESTDIR/usr/bin/geos-config \
83+
--with-hide-internal-symbols=yes \
84+
CFLAGS="-O2 -Os" CXXFLAGS="-O2 -Os"; \
85+
make ; make install; make install DESTDIR= ; \
86+
cd $BUILD; rm -rf gdal-$GDAL_VERSION*
87+
88+
RUN \
89+
git clone https://github.com/PDAL/PDAL.git; \
90+
cd PDAL; \
91+
mkdir -p _build; \
92+
cd _build; \
93+
cmake .. \
94+
-G "Unix Makefiles" \
95+
-DCMAKE_BUILD_TYPE=Release \
96+
-DCMAKE_CXX_FLAGS="-std=c++11" \
97+
-DCMAKE_MAKE_PROGRAM=make \
98+
-DBUILD_PLUGIN_I3S=ON \
99+
-DWITH_LASZIP=ON \
100+
-DCMAKE_LIBRARY_PATH:FILEPATH="$DESTDIR/usr/lib" \
101+
-DCMAKE_INCLUDE_PATH:FILEPATH="$DESTDIR/usr/include" \
102+
-DCMAKE_INSTALL_PREFIX=$PREFIX \
103+
-DWITH_TESTS=OFF \
104+
-DCMAKE_INSTALL_LIBDIR=lib \
105+
; \
106+
make ; make install; make install DESTDIR= ;
107+
108+
RUN rm /build/usr/lib/*.la ; rm /build/usr/lib/*.a
109+
RUN ldconfig
110+
ADD package-pdal.sh /
111+

README.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
================================================================================
2+
PDAL Lambda Layer for AWS
3+
================================================================================
4+
5+
In December 2018, AWS released `Lambda Layers`_, which allow you to stack together
6+
software runtime layers with AWS Lambda functions. Layers relax the requirements that
7+
single Lambda functions must be less than 50mb, and now allow you to stack up to
8+
five layers at 50mb each, and these layers can be composed with versioning and
9+
other AWS management facilities that you would expect to use.
10+
11+
This repository borrows concepts from Development Seed's `GeoLambda`_ project, but
12+
it simplifies the effort to a few things:
13+
14+
1. Build a Docker container based on https://github.com/lambci/lambci for `PDAL`_
15+
and its dependencies
16+
17+
2. Construct a ``.zip`` file package of the binaries and ``.so`` libraries needed
18+
to run PDAL and GDAL as a Lambda Layer
19+
20+
3. Provide a script to create a public PDAL Lambda Layer using the package
21+
22+
Instructions
23+
--------------------------------------------------------------------------------
24+
25+
1. Build the Package. It's going to run docker and do a bunch of stuff. At the
26+
end when it is successful, you should have a ``lambda-deploy.zip`` file
27+
in your directory.
28+
29+
::
30+
31+
$ ./build.sh
32+
33+
2. Set your ``AWS_PROFILE`` and ``AWS_REGION`` variables:
34+
35+
36+
::
37+
38+
$ export AWS_PROFILE=hobu
39+
$ export AWS_REGION=us-east-1
40+
41+
3. Execute the ``create-lambda-layer.sh`` bash script. It requires the `jq`_
42+
command in your path.
43+
44+
::
45+
46+
$ ./create-lambda-layer.sh
47+
Published version 6 for Lambda layer pdal
48+
Setting execution access to public for version 6 for Lambda layer pdal
49+
Layer pdal is available at 'arn:aws:lambda:us-east-1:163178234892:layer:pdal'
50+
51+
_`Lambda Layers`: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html
52+
_`GeoLambda`: https://github.com/developmentseed/geolambda
53+
_`jq`: https://stedolan.github.io/jq/
54+
_`PDAL`: https://pdal.io

build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
CONTAINER="pdal-lambda"
4+
docker build -t $CONTAINER -f Dockerfile .
5+
rm -rf lambda
6+
mkdir -p lambda
7+
8+
docker run -v `pwd`:/output $CONTAINER /package-pdal.sh

create-lambda-layer.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
LAYERNAME="pdal"
3+
LAYER=$(aws lambda publish-layer-version \
4+
--layer-name $LAYERNAME \
5+
--description "PDAL 1.8.0 softare" \
6+
--zip-file fileb://./lambda-deploy.zip \
7+
--compatible-runtimes "provided" \
8+
--license-info BSD \
9+
--region $AWS_REGION \
10+
--profile $AWS_PROFILE)
11+
12+
13+
VERSION=$(aws lambda list-layers --region $AWS_REGION |jq '.Layers[]| select(.LayerName=="'$LAYERNAME'").LatestMatchingVersion.Version' -r)
14+
15+
echo "Published version $VERSION for Lambda layer $LAYERNAME"
16+
17+
LAYER=$(aws lambda get-layer-version \
18+
--layer-name pdal \
19+
--version-number $VERSION \
20+
--region $AWS_REGION \
21+
--profile $AWS_PROFILE)
22+
23+
24+
echo "Setting execution access to public for version $VERSION for Lambda layer $LAYERNAME"
25+
PERMISSION=$(aws lambda add-layer-version-permission \
26+
--layer-name pdal \
27+
--version-number $VERSION \
28+
--statement-id "run-pdal-publicly" \
29+
--principal '*' \
30+
--action lambda:GetLayerVersion \
31+
--region $AWS_REGION \
32+
--profile $AWS_PROFILE )
33+
34+
LAYERARN=$(echo $LAYER | jq -r .LayerArn)
35+
36+
echo "Layer $LAYERNAME is available at '$LAYERARN'"
37+

package-pdal.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
3+
export DEPLOY_DIR=/output/lambda
4+
5+
PACKAGE_NAME="lambda-deploy.zip"
6+
7+
# make deployment directory and add lambda handler
8+
cp -r /build/usr/lib $DEPLOY_DIR/lib
9+
cp -r /build/usr/bin $DEPLOY_DIR/bin
10+
cp /usr/lib64/libjpeg.so.62.0.0 $DEPLOY_DIR/lib/
11+
cp /usr/lib64/libxml2.so.2.9.1 $DEPLOY_DIR/lib/
12+
cp /usr/lib64/liblzma.so.5.0.99 $DEPLOY_DIR/lib/
13+
cp /usr/lib64/libtiff.so.5.2.0 $DEPLOY_DIR/lib/
14+
cp /usr/lib64/libpng.so.3.49.0 $DEPLOY_DIR/lib/
15+
cp /usr/lib64/libsqlite3.so.0.8.6 $DEPLOY_DIR/lib/
16+
rm -rf $DEPLOY_DIR/lib/*.a
17+
rm -rf $DEPLOY_DIR/lib/libpdal_plugin*
18+
rm -rf $DEPLOY_DIR/lib/python3.6
19+
20+
rsync -ax /build/usr/share/gdal $DEPLOY_DIR/share/
21+
rsync -ax /build/usr/share/proj $DEPLOY_DIR/share/
22+
23+
cd $DEPLOY_DIR
24+
zip -ruq ../$PACKAGE_NAME ./
25+
rm -rf $DEPLOY_DIR
26+
27+
28+

0 commit comments

Comments
 (0)