This repository has been archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
cloudformation.yaml
133 lines (129 loc) · 5.12 KB
/
cloudformation.yaml
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
AWSTemplateFormatVersion: 2010-09-09
Resources:
LogGroup:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: !Sub "/aws/codebuild/${AWS::StackName}"
RetentionInDays: 30
Role:
Type: AWS::IAM::Role
Properties:
RoleName: !Ref AWS::StackName
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
Action: sts:AssumeRole
Principal:
Service: codebuild.amazonaws.com
Effect: Allow
Policies:
- PolicyName: policy
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
Resource: !GetAtt LogGroup.Arn
- Effect: Allow
Action:
- lambda:PublishLayerVersion
Resource: !Sub "arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:layer:${AWS::StackName}*"
Project:
Type: AWS::CodeBuild::Project
Properties:
Name: !Ref AWS::StackName
Environment:
ComputeType: BUILD_GENERAL1_LARGE
Type: LINUX_CONTAINER
Image: amazonlinux:2
ServiceRole: !Ref Role
Source:
Type: NO_SOURCE
BuildSpec: !Sub |-
version: 0.2
env:
variables:
LAYER_NAME: ${AWS::StackName}
LAYER_DESCRIPTION: gdal 3.0.4 for python3.8 with netcdf/hdf5 support
phases:
build:
commands:
# install build tools and dependencies available via yum
- yum install -y gcc gcc-c++ make libtool file gzip zip wget openssl-devel libffi-devel
- yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- yum install -y netcdf-devel hdf5-devel
# create folders for deployment package
- mkdir /opt/python
- mkdir /opt/lib
- mkdir /opt/lib/data
- export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
# install python and pip 3.8.1
- wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz
- tar xzf Python-3.8.1.tgz
- cd Python-3.8.1
- ./configure
- make -j $(nproc)
- make install
- cd ..
# install sqlite
- wget https://www.sqlite.org/snapshot/sqlite-snapshot-202002181949.tar.gz
- tar xvzf sqlite-snapshot-202002181949.tar.gz
- cd sqlite-snapshot-202002181949
- ./configure
- make -j $(nproc)
- make install
- cd ..
# install proj 6.3.1
- wget https://github.com/OSGeo/PROJ/releases/download/6.3.1/proj-6.3.1.tar.gz
- tar xvzf proj-6.3.1.tar.gz
- cd proj-6.3.1
- ./configure --datarootdir=/opt/lib/data
- make -j $(nproc)
- make install
- cd ..
# install gdal 3.0.4
- wget https://github.com/OSGeo/gdal/releases/download/v3.0.4/gdal-3.0.4.tar.gz
- tar xvzf gdal-3.0.4.tar.gz
- cd gdal-3.0.4
- ./configure --with-proj --datarootdir=/opt/lib/data > /opt/configure.txt
- make -j $(nproc)
- make install
- cd ../..
# copy libraries into deployment package
- cp /usr/local/lib/libgdal.so.26 /opt/lib/
- cp /usr/local/lib/libproj.so.15 /opt/lib/
- cp /usr/local/lib/libsqlite3.so.0 /opt/lib/
- cp /usr/lib64/libnetcdf.so.7 /opt/lib/
- cp /usr/lib64/libhdf5.so.8 /opt/lib/
- cp /usr/lib64/libhdf5_hl.so.8 /opt/lib/
- cp /usr/lib64/libsz.so.2 /opt/lib/
- cp /usr/lib64/libaec.so.0 /opt/lib/
- cp /usr/lib64/libcurl.so.4 /opt/lib/
- cp /usr/lib64/libjpeg.so.62 /opt/lib/
- cp /usr/lib64/libnghttp2.so.14 /opt/lib/
- cp /usr/lib64/libidn2.so.0 /opt/lib/
- cp /usr/lib64/libssh2.so.1 /opt/lib/
- cp /usr/lib64/libldap-2.4.so.2 /opt/lib/
- cp /usr/lib64/liblber-2.4.so.2 /opt/lib/
- cp /usr/lib64/libunistring.so.0 /opt/lib/
- cp /usr/lib64/libsasl2.so.3 /opt/lib/
- cp /usr/lib64/libssl3.so /opt/lib/
- cp /usr/lib64/libsmime3.so /opt/lib/
- cp /usr/lib64/libnss3.so /opt/lib/
- strip /opt/lib/*.so*
# install gdal python bindings into deployment package
- pip3.8 install -t /opt/python/ gdal==3.0.4
# zip and deploy package
- cd /opt
- zip -r gdal-layer.zip *
- pip3.8 install awscli
- aws lambda publish-layer-version --layer-name $LAYER_NAME --description "$LAYER_DESCRIPTION" --compatible-runtimes python3.8 --license-info MIT --zip-file fileb://gdal-layer.zip
Artifacts:
Type: NO_ARTIFACTS
LogsConfig:
CloudWatchLogs:
Status: ENABLED
GroupName: !Ref LogGroup
TimeoutInMinutes: 30