├── .github └── workflows │ └── build.yml ├── .gitignore ├── LICENSE ├── README.rst ├── data └── autzen-classified.copc.laz ├── docker ├── Dockerfile.runner ├── build-environment.yml ├── info-event.tftpl ├── python-entry.sh ├── root-bashrc ├── run-environment.yml ├── run-local.sh ├── test-event.json ├── test-local.sh └── test-remote.sh ├── handlers └── python │ └── ecr │ ├── __init__.py │ ├── info.py │ └── util.py └── terraform ├── main.tf ├── pdal.tfvars ├── requirements.txt └── resources ├── data.tf ├── ecr.tf ├── lambda.tf ├── roles.tf ├── storage.tf └── var.tf /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | pull_request: 6 | workflow_dispatch: 7 | schedule: 8 | - cron: '40 7 * * 2' 9 | 10 | 11 | 12 | jobs: 13 | 14 | config: 15 | runs-on: ubuntu-latest 16 | outputs: 17 | matrix: ${{ steps.set-matrix.outputs.matrix }} 18 | steps: 19 | - id: set-matrix 20 | run: echo "::set-output name=matrix::{\"include\":[{\"type\":\"amd64\",\"image\":\"amazon/aws-lambda-provided:al2\", \"arch\":\"x86_64\"},{\"type\":\"arm64\",\"image\":\"amazon/aws-lambda-provided:al2.2023.12.14.13\", \"arch\":\"arm64\"}] }" 21 | 22 | 23 | containers: 24 | needs: config 25 | runs-on: ubuntu-latest 26 | permissions: 27 | packages: write 28 | strategy: 29 | fail-fast: true 30 | matrix: ${{fromJson(needs.config.outputs.matrix)}} 31 | env: 32 | PUSH_PACKAGES: ${{ github.repository_owner == 'PDAL' && github.event_name != 'pull_request'}} 33 | steps: 34 | - uses: actions/checkout@v3 35 | - name: Set up QEMU 36 | uses: docker/setup-qemu-action@v2 37 | 38 | - name: Lint 39 | id: lint 40 | run: | 41 | echo "are we pushing packages" ${{ env.PUSH_PACKAGES }} 42 | echo "event_name" ${{ github.event_name }} 43 | echo "ref" ${{ github.ref }} 44 | - name: Setup Docker Buildx 45 | id: buildx 46 | uses: docker/setup-buildx-action@v3 47 | with: 48 | version: latest 49 | - if: ${{ env.PUSH_PACKAGES == 'true' }} 50 | name: Login to GitHub Container Registry 51 | uses: docker/login-action@v3 52 | with: 53 | registry: ghcr.io 54 | username: ${{ github.actor }} 55 | password: ${{ secrets.GITHUB_TOKEN }} 56 | - name: Prepare 57 | id: prep 58 | run: | 59 | VERSION=sha-${GITHUB_SHA::8} 60 | if [[ $GITHUB_REF == refs/tags/* ]]; then 61 | VERSION=${GITHUB_REF/refs\/tags\//} 62 | fi 63 | echo ::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ') 64 | echo ::set-output name=VERSION::${VERSION} 65 | - name: Build image 66 | uses: docker/build-push-action@v5 67 | with: 68 | push: ${{ env.PUSH_PACKAGES == 'true' }} 69 | builder: ${{ steps.buildx.outputs.name }} 70 | context: . 71 | file: ./Dockerfile 72 | platforms: linux/${{ matrix.type}} 73 | build-args: | 74 | LAMBDA_IMAGE=${{ matrix.image }} 75 | RIE_ARCH=${{ matrix.arch }} 76 | tags: | 77 | ghcr.io/pdal/lambda:${{ steps.prep.outputs.VERSION }} 78 | ghcr.io/pdal/lambda:latest 79 | labels: | 80 | org.opencontainers.image.title=${{ github.event.repository.name }} 81 | org.opencontainers.image.description=${{ github.event.repository.description }} 82 | org.opencontainers.image.source=${{ github.event.repository.html_url }} 83 | org.opencontainers.image.url=${{ github.event.repository.html_url }} 84 | org.opencontainers.image.revision=${{ github.sha }} 85 | org.opencontainers.image.version=${{ steps.prep.outputs.VERSION }} 86 | org.opencontainers.image.created=${{ steps.prep.outputs.BUILD_DATE }} 87 | 88 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.tfstate* 2 | *.hcl 3 | .terraform/ 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | PDAL Lambda Container for AWS 3 | ================================================================================ 4 | 5 | Instructions 6 | -------------------------------------------------------------------------------- 7 | 8 | 9 | Note that this set of scripts has only been run on an M1/M2 Mac. Multi-arch 10 | containers are often quite slow. 11 | 12 | 0. Set your AWS variables into your environment: 13 | 14 | :: 15 | 16 | AWS_ACCESS_KEY_ID=something 17 | AWS_SECRET_ACCESS_KEY=somethingelse 18 | AWS_DEFAULT_REGION=us-east-1 19 | 20 | 1. (optional) Edit your variables 21 | 22 | :: 23 | 24 | cat terraform/pdal.tfvars 25 | 26 | environment_name="pdal-lambda" 27 | arch="arm64" 28 | 29 | 2. Initialize your Terraform Environment 30 | 31 | :: 32 | 33 | cd terraform 34 | terraform init 35 | terraform validate 36 | terraform apply -var-file pdal.tfvars 37 | 38 | The Terraform configuration will create some resources including an ECR 39 | repository to store the image, a role for execution of the lambda, 40 | and the lambda itself. Adjust your configuration as needed in `./terraform/resources` 41 | 42 | 3. Test locally 43 | 44 | Fire up the Lambda Docker container in one terminal: 45 | 46 | :: 47 | 48 | cd docker 49 | ./run-local.sh /var/task/python-entry.sh pdal_lambda.ecr.info.handler 50 | 51 | In another terminal, issue the test. Note that it currently defaults to running 52 | on port 9000. Adjust the script as necessary. 53 | 54 | :: 55 | 56 | cd docker 57 | ./test-local.sh info-event.json 58 | 59 | 4. Test remotely 60 | 61 | 62 | :: 63 | 64 | cd docker 65 | ./test-remote.sh info-event.json 66 | cat response.json 67 | 68 | -------------------------------------------------------------------------------- /data/autzen-classified.copc.laz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDAL/lambda/0ae45e31e8c6b330855bbe19c862e214c095fcee/data/autzen-classified.copc.laz -------------------------------------------------------------------------------- /docker/Dockerfile.runner: -------------------------------------------------------------------------------- 1 | ARG LAMBDA_IMAGE="amazon/aws-lambda-provided:al2" 2 | ARG RIE_ARCH="amd64" 3 | 4 | FROM --platform=$TARGETPLATFORM condaforge/miniforge3:latest as condasetup 5 | LABEL MAINTAINER="Howard Butler " 6 | 7 | ARG TARGETPLATFORM 8 | ARG TARGETARCH 9 | ARG TARGETVARIANT 10 | RUN printf "I'm building for TARGETPLATFORM=${TARGETPLATFORM}" \ 11 | && printf ", TARGETARCH=${TARGETARCH}" \ 12 | && printf ", TARGETVARIANT=${TARGETVARIANT} \n" \ 13 | && printf "With uname -s : " && uname -s \ 14 | && printf "and uname -m : " && uname -mm 15 | 16 | ENV CONDA_ENV_NAME "pdal" 17 | ENV CONDAENV "/opt/conda/envs/${CONDA_ENV_NAME}" 18 | 19 | 20 | # Create the environment: 21 | COPY build-environment.yml . 22 | RUN conda env create -f build-environment.yml 23 | RUN mamba update --all -y 24 | 25 | COPY run-environment.yml . 26 | RUN conda env create -f run-environment.yml 27 | 28 | 29 | SHELL ["conda", "run", "-n", "build", "/bin/bash", "-c"] 30 | RUN conda-pack -n ${CONDA_ENV_NAME} --dest-prefix=/var/task -o /tmp/env.tar && \ 31 | mkdir /venv && cd /venv && tar xf /tmp/env.tar && \ 32 | rm /tmp/env.tar 33 | 34 | 35 | FROM --platform=$TARGETPLATFORM ${LAMBDA_IMAGE:?} as al2 36 | 37 | ARG RIE_ARCH 38 | ARG LAMBDA_IMAGE 39 | ARG TARGETPLATFORM 40 | ARG TARGETARCH 41 | ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} 42 | ENV TARGETARCH=${TARGETARCH:-amd64} 43 | 44 | 45 | 46 | ENV CONDAENV "/var/task" 47 | ENV CONDA_PREFIX "/var/task" 48 | ENV TARGETPLATFORM "${TARGETPLATFORM}" 49 | COPY --from=condasetup /venv ${CONDAENV} 50 | 51 | 52 | 53 | ENV PROJ_LIB ${CONDAENV}/share/proj 54 | ENV PROJ_NETWORK=TRUE 55 | ENV PATH $PATH:${CONDAENV}/bin 56 | ENV LD_LIBRARY_PATH=${CONDAENV}/lib 57 | ENV HOME=/var/task/ 58 | 59 | RUN /var/task/bin/python -m pip install awslambdaric==2.0.11 60 | ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie-${RIE_ARCH} /usr/bin/aws-lambda-rie 61 | 62 | RUN chmod +x /usr/bin/aws-lambda-rie 63 | 64 | 65 | WORKDIR /var/task 66 | COPY python-entry.sh ./ 67 | COPY handlers/python/ /var/task/lib/python3.11/site-packages/pdal_lambda 68 | COPY root-bashrc /root/.bashrc 69 | ENTRYPOINT [ "/var/task/python-entry.sh" ] 70 | -------------------------------------------------------------------------------- /docker/build-environment.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - conda-pack 6 | - compilers 7 | - ninja 8 | - cmake 9 | - pdal 10 | - eigen 11 | - unzip 12 | -------------------------------------------------------------------------------- /docker/info-event.tftpl: -------------------------------------------------------------------------------- 1 | { 2 | "Records": [ 3 | { 4 | "eventVersion": "2.1", 5 | "eventSource": "aws:s3", 6 | "awsRegion": "us-east-1", 7 | "eventTime": "2019-09-03T19:37:27.192Z", 8 | "eventName": "ObjectCreated:Put", 9 | "userIdentity": { 10 | "principalId": "AWS:AIDAINPONIXQXHT3IKHL2" 11 | }, 12 | "requestParameters": { 13 | "sourceIPAddress": "205.255.255.255" 14 | }, 15 | "responseElements": { 16 | "x-amz-request-id": "D82B88E5F771F645", 17 | "x-amz-id-2": "vlR7PnpV2Ce81l0PRw6jlUpck7Jo5ZsQjryTjKlc5aLWGVHPZLj5NeC6qMa0emYBDXOo6QBU0Wo=" 18 | }, 19 | "s3": { 20 | "s3SchemaVersion": "1.0", 21 | "configurationId": "828aa6fc-f7b5-4305-8584-487c791949c1", 22 | "bucket": { 23 | "name": "${ bucket}", 24 | "ownerIdentity": { 25 | "principalId": "A3I5XTEXAMAI3E" 26 | }, 27 | "arn": "arn:aws:s3:::lambda-artifacts-deafc19498e3f2df" 28 | }, 29 | "object": { 30 | "key": "autzen-classified.copc.laz", 31 | "size": 1305107, 32 | "eTag": "b21b84d653bb07b05b1e6b33684dc11b", 33 | "sequencer": "0C0F6F405D6ED209E1" 34 | } 35 | } 36 | } 37 | ] 38 | } 39 | 40 | -------------------------------------------------------------------------------- /docker/python-entry.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | env 4 | if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then 5 | exec /usr/bin/aws-lambda-rie /var/task/bin/python -m awslambdaric $1 6 | else 7 | exec /var/task/bin/python -m awslambdaric $1 8 | fi 9 | 10 | 11 | -------------------------------------------------------------------------------- /docker/root-bashrc: -------------------------------------------------------------------------------- 1 | # >>> conda initialize >>> 2 | # !! Contents within this block are managed by 'conda init' !! 3 | __conda_setup="$('/var/task/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" 4 | if [ $? -eq 0 ]; then 5 | eval "$__conda_setup" 6 | else 7 | if [ -f "/var/task/etc/profile.d/conda.sh" ]; then 8 | . "/var/task/etc/profile.d/conda.sh" 9 | else 10 | export PATH="/var/task/bin:$PATH" 11 | fi 12 | fi 13 | unset __conda_setup 14 | -------------------------------------------------------------------------------- /docker/run-environment.yml: -------------------------------------------------------------------------------- 1 | name: pdal 2 | channels: 3 | - conda-forge 4 | dependencies: 5 | - python-pdal 6 | - python=3.11 7 | - aws-sdk-cpp 8 | - shapely 9 | - gdal 10 | - pyproj 11 | - pystac 12 | - stactools 13 | - nodejs 14 | - whitebox_tools 15 | - boto3 16 | - awscli 17 | - pip 18 | - eigen 19 | - matplotlib 20 | - unzip 21 | - requests 22 | - geocoder 23 | - untwine 24 | - pip: 25 | - trenchrun 26 | - cloudpathlib 27 | - ept-python 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /docker/run-local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ./run-local.sh /var/task/python-entry.sh pdal_lambda.ecr.info.handler 4 | 5 | entrypoint="$1" 6 | command="$2" 7 | 8 | CONTAINER=$(cat ../terraform/terraform.tfstate | jq '.outputs.container.value // empty' -r) 9 | 10 | REGION=$AWS_DEFAULT_REGION 11 | if [ -z "$REGION" ] 12 | then 13 | echo "AWS_DEFAULT_REGION must be set!" 14 | exit 1; 15 | fi 16 | 17 | LOCALPORT=9000 18 | REMOTEPORT=8080 19 | 20 | KEY_ID=$(aws --profile $AWS_DEFAULT_PROFILE configure get aws_access_key_id) 21 | SECRET_ID=$(aws --profile $AWS_DEFAULT_PROFILE configure get aws_secret_access_key) 22 | 23 | 24 | echo "Starting container $CONTAINER" 25 | 26 | if [ -z "$entrypoint" ] 27 | then 28 | echo "executing default entrypoint using $command" 29 | docker run -p $LOCALPORT:$REMOTEPORT \ 30 | -e AWS_DEFAULT_REGION=$REGION \ 31 | -e AWS_ACCESS_KEY_ID=${KEY_ID} \ 32 | -e AWS_SECRET_ACCESS_KEY=${SECRET_ID} \ 33 | $CONTAINER "$command" 34 | else 35 | echo "executing with $entrypoint and command '$command'" 36 | docker run -p $LOCALPORT:$REMOTEPORT \ 37 | -e AWS_DEFAULT_REGION=$REGION \ 38 | -e AWS_ACCESS_KEY_ID=$KEY_ID \ 39 | -e AWS_SECRET_ACCESS_KEY=$SECRET_ID \ 40 | -t -i \ 41 | -v $(pwd):/data \ 42 | --entrypoint=$entrypoint \ 43 | $CONTAINER "$command" 44 | fi 45 | 46 | -------------------------------------------------------------------------------- /docker/test-event.json: -------------------------------------------------------------------------------- 1 | { 2 | "pipeline": [ 3 | { 4 | "bounds": "([-10425171.940, -10423171.940], [5164494.710, 5166494.710])", 5 | "filename": "https://s3-us-west-2.amazonaws.com/usgs-lidar-public/IA_FullState/ept.json", 6 | "resolution":5, 7 | "requests":1, 8 | "type": "readers.ept", 9 | "tag": "readdata" 10 | }, 11 | { 12 | "expression": "Classification != 7", 13 | "type": "filters.expression", 14 | "tag": "nonoise" 15 | }, 16 | { 17 | "assignment": "Classification[:]=0", 18 | "tag": "wipeclasses", 19 | "type": "filters.assign" 20 | }, 21 | { 22 | "out_srs": "EPSG:26915", 23 | "tag": "reprojectUTM", 24 | "type": "filters.reprojection" 25 | }, 26 | { 27 | "tag": "groundify", 28 | "type": "filters.smrf" 29 | }, 30 | { 31 | "expression": "Classification == 2", 32 | "type": "filters.expression", 33 | "tag": "classify" 34 | }, 35 | { 36 | "filename": "iowa.laz", 37 | "inputs": [ "classify" ], 38 | "tag": "writerslas", 39 | "type": "writers.las" 40 | }, 41 | { 42 | "filename": "iowa.tif", 43 | "gdalopts": "tiled=yes, compress=deflate", 44 | "inputs": [ "writerslas" ], 45 | "nodata": -9999, 46 | "output_type": "idw", 47 | "resolution": 5, 48 | "type": "writers.gdal", 49 | "window_size": 3 50 | } 51 | ], 52 | "Records": [ 53 | { 54 | "eventVersion": "2.1", 55 | "eventSource": "aws:s3", 56 | "awsRegion": "us-east-1", 57 | "eventTime": "2019-09-03T19:37:27.192Z", 58 | "eventName": "ObjectCreated:Put", 59 | "userIdentity": { 60 | "principalId": "AWS:AIDAINPONIXQXHT3IKHL2" 61 | }, 62 | "requestParameters": { 63 | "sourceIPAddress": "205.255.255.255" 64 | }, 65 | "responseElements": { 66 | "x-amz-request-id": "D82B88E5F771F645", 67 | "x-amz-id-2": "vlR7PnpV2Ce81l0PRw6jlUpck7Jo5ZsQjryTjKlc5aLWGVHPZLj5NeC6qMa0emYBDXOo6QBU0Wo=" 68 | }, 69 | "s3": { 70 | "s3SchemaVersion": "1.0", 71 | "configurationId": "828aa6fc-f7b5-4305-8584-487c791949c1", 72 | "bucket": { 73 | "name": "grid-dev-lidarscans", 74 | "ownerIdentity": { 75 | "principalId": "A3I5XTEXAMAI3E" 76 | }, 77 | "arn": "arn:aws:s3:::lambda-artifacts-deafc19498e3f2df" 78 | }, 79 | "object": { 80 | "key": "RiPS/jpg/INGLEFIELD_RIPS_puck_20190708_210000.jpg", 81 | "size": 1305107, 82 | "eTag": "b21b84d653bb07b05b1e6b33684dc11b", 83 | "sequencer": "0C0F6F405D6ED209E1" 84 | } 85 | } 86 | } 87 | ] 88 | 89 | } 90 | -------------------------------------------------------------------------------- /docker/test-local.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | eventfilename=$1 4 | 5 | if [ -z "$AWS_ACCESS_KEY_ID" ] 6 | then 7 | echo "AWS_ACCESS_KEY_ID must be set in environment!" 8 | exit 1; 9 | fi 10 | 11 | if [ -z "$AWS_SECRET_ACCESS_KEY" ] 12 | then 13 | echo "AWS_SECRET_ACCESS_KEY must be set in environment!" 14 | exit 1; 15 | fi 16 | 17 | 18 | event=$(<$eventfilename) 19 | echo $event 20 | curl -POST -v "http://localhost:9000/2015-03-31/functions/function/invocations" -d @$eventfilename 21 | 22 | 23 | -------------------------------------------------------------------------------- /docker/test-remote.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | eventfilename=$1 4 | 5 | FUNCTION_NAME=$(cat ../terraform/terraform.tfstate | jq '.outputs.info_lambda_name.value // empty' -r) 6 | 7 | if [ -z "$AWS_ACCESS_KEY_ID" ] 8 | then 9 | echo "AWS_ACCESS_KEY_ID must be set in environment!" 10 | exit 1; 11 | fi 12 | 13 | if [ -z "$AWS_SECRET_ACCESS_KEY" ] 14 | then 15 | echo "AWS_SECRET_ACCESS_KEY must be set in environment!" 16 | exit 1; 17 | fi 18 | 19 | aws lambda invoke \ 20 | --function-name "$FUNCTION_NAME" \ 21 | --invocation-type RequestResponse \ 22 | --payload fileb://$eventfilename \ 23 | response.json 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /handlers/python/ecr/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PDAL/lambda/0ae45e31e8c6b330855bbe19c862e214c095fcee/handlers/python/ecr/__init__.py -------------------------------------------------------------------------------- /handlers/python/ecr/info.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | from pathlib import Path 4 | 5 | import logging 6 | 7 | # set up logger for CloudWatch 8 | logger = logging.getLogger(__file__) 9 | logger.setLevel(logging.DEBUG) 10 | 11 | from . import util 12 | 13 | def handler(event, context): 14 | """Takes a PDAL pipeline and executes it""" 15 | 16 | logger.debug("'info_handler' handler called") 17 | logger.debug(event) 18 | 19 | 20 | infos = [] 21 | for path in util.extract_records(event['Records']): # yields s3path 22 | 23 | logger.debug(f'processing {path}') 24 | 25 | 26 | 27 | command = f'pdal info --debug {path.as_uri()}' 28 | env = os.environ.copy() 29 | 30 | # env['VERBOSE'] = "1" 31 | 32 | response = util.run(command, env = env) 33 | logger.debug(f'response {response}') 34 | 35 | j = json.loads(response) 36 | infos.append(j) 37 | 38 | return infos 39 | 40 | 41 | -------------------------------------------------------------------------------- /handlers/python/ecr/util.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | from cloudpathlib import S3Path 5 | 6 | import logging 7 | import subprocess 8 | import shlex 9 | 10 | # set up logger for CloudWatch 11 | logger = logging.getLogger(__file__) 12 | logger.setLevel(logging.DEBUG) 13 | 14 | 15 | def run(cargs, working_dir=None, env = None): 16 | cargs = shlex.split(cargs) 17 | logger.debug(" ".join(cargs)) 18 | if env: 19 | local_env = env 20 | else: 21 | local_env = os.environ.copy() 22 | 23 | p = subprocess.Popen( 24 | cargs, 25 | stdin=subprocess.PIPE, 26 | stdout=subprocess.PIPE, 27 | stderr=subprocess.PIPE, 28 | encoding="utf8", 29 | cwd = working_dir, 30 | env = local_env, 31 | ) 32 | ret = p.communicate() 33 | 34 | body, error = ret 35 | if p.returncode != 0: 36 | logger.error(cargs) 37 | logger.error(error) 38 | error = {"args": cargs, "error": error, "body": body} 39 | raise AttributeError(error) 40 | 41 | return body 42 | 43 | 44 | 45 | 46 | def extract_records(records): 47 | 48 | # prefixes = [] 49 | 50 | for record in records: 51 | 52 | handle = None 53 | if 'receiptHandle' in record: 54 | handle = record['receiptHandle'] 55 | 56 | logger.debug(f"message {record}") 57 | 58 | if record['eventSource'] == 'aws:sqs': 59 | # pipeline comes through record['body'] as text 60 | body = json.loads(record['body']) 61 | logger.debug(f"body {body}") 62 | message = json.loads(body['Message']) 63 | logger.debug(f"message {message}") 64 | bucket = message['bucket'] 65 | key = message['key'].strip('/') 66 | 67 | if record['eventSource'] == 'aws:sns': 68 | # pipeline comes through record['body'] as text 69 | message = json.loads(record['message']) 70 | bucket = message['bucket'] 71 | key = message['key'].strip('/') 72 | 73 | elif record['eventSource'] == 'aws:s3': 74 | 75 | # pipeline is the bucket/key 76 | bucket = record['s3']['bucket']['name'] 77 | key = record['s3']['object']['key'] 78 | 79 | key = key.lstrip('/') 80 | # uri = os.path.join('s3://', bucket, key) 81 | uri = f's3://{bucket}/{key}' 82 | key = S3Path(uri) 83 | yield key 84 | 85 | -------------------------------------------------------------------------------- /terraform/main.tf: -------------------------------------------------------------------------------- 1 | module "resources" { 2 | source = "./resources" 3 | 4 | prefix = var.environment_name 5 | arch = var.arch 6 | stage = var.stage 7 | 8 | } 9 | 10 | variable "environment_name" { 11 | type = string 12 | } 13 | 14 | variable "arch" { 15 | type = string 16 | default = "arm64" 17 | } 18 | 19 | variable "stage" { 20 | type = string 21 | default = "dev" 22 | } 23 | 24 | 25 | 26 | 27 | 28 | 29 | output "environment" { 30 | description = "Environment name" 31 | value = module.resources.prefix 32 | } 33 | 34 | output "arch" { 35 | description = "ECR Architecture (amd64 or arm64)" 36 | value = var.arch 37 | } 38 | 39 | output "stage" { 40 | description = "Deployment stage" 41 | value = var.stage 42 | } 43 | 44 | 45 | 46 | output "info_lambda_name" { 47 | description = "Lambda Name" 48 | value = module.resources.info_lambda_name 49 | } 50 | 51 | output "bucket" { 52 | description = "Storage bucket" 53 | value = module.resources.bucket 54 | } 55 | 56 | output "container" { 57 | description = "Container ARN" 58 | value = module.resources.container 59 | } 60 | -------------------------------------------------------------------------------- /terraform/pdal.tfvars: -------------------------------------------------------------------------------- 1 | environment_name="pdal-lambda" 2 | arch="arm64" 3 | -------------------------------------------------------------------------------- /terraform/requirements.txt: -------------------------------------------------------------------------------- 1 | s3path 2 | boto3 3 | pyyaml 4 | requests 5 | 6 | 7 | -------------------------------------------------------------------------------- /terraform/resources/data.tf: -------------------------------------------------------------------------------- 1 | data "aws_region" "current" { } 2 | 3 | data "aws_caller_identity" "current" { } 4 | 5 | 6 | -------------------------------------------------------------------------------- /terraform/resources/ecr.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | ecr_repository_name = "${var.prefix}-${var.stage}-pdal_runner" 3 | } 4 | 5 | resource aws_ecr_repository runner_ecr_repo { 6 | name = local.ecr_repository_name 7 | image_tag_mutability = "MUTABLE" 8 | force_delete = true 9 | } 10 | 11 | resource null_resource ecr_image { 12 | triggers = { 13 | docker_file = md5(file("${path.root}/../docker/Dockerfile.runner")) 14 | environment_file = md5(file("${path.root}/../docker/run-environment.yml")) 15 | entry_file = md5(file("${path.root}/../docker/python-entry.sh")) 16 | handlers = sha1(join("", [for f in fileset("${path.root}/../handlers/", "**"): filesha1("${path.root}/../handlers/${f}")])) 17 | } 18 | 19 | provisioner "local-exec" { 20 | command = < \"%s\"\n%s\nEOF", 54 | "${path.root}/../docker/info-event.json", 55 | local.our_rendered_content 56 | ) 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /terraform/resources/var.tf: -------------------------------------------------------------------------------- 1 | //VARIABLES 2 | 3 | variable "prefix" { 4 | type = string 5 | } 6 | 7 | 8 | variable "stage" { 9 | type = string 10 | default = "dev" 11 | } 12 | 13 | variable "arch" { 14 | type = string 15 | default = "arm64" 16 | } 17 | 18 | variable "function_timeout" { 19 | type = number 20 | default = 300 21 | } 22 | 23 | 24 | variable "lambda_python_runtime" { 25 | type = string 26 | default = "python3.10" 27 | } 28 | 29 | 30 | output "prefix" { 31 | description = "prefix" 32 | value = var.prefix 33 | } 34 | 35 | 36 | 37 | --------------------------------------------------------------------------------