├── .gitignore ├── LICENSE.txt ├── README.md ├── config.py ├── mapproxy.yaml ├── requirements.txt └── serverless.yml /.gitignore: -------------------------------------------------------------------------------- 1 | env/ 2 | .*/ 3 | node_modules/ 4 | package-lock.json 5 | package.json 6 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2017, RemotePixel.ca 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Lambda MapProxy 2 | 3 | A basic [Serverless](https://serverless.com) setup to run MapProxy as an Amazon Web Service Lambda Function. 4 | 5 | You will need to have an Amazon IAM user set up with valid credentials in your environment. Instructions for this can be found [here](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html). 6 | 7 | You will need to create an s3 bucket (this is where the cached tiles are stored). In the serverless.yml file, you will need to change line 16 from "mapproxy-lambda-demo" to your bucket name. 8 | 9 | Likewise you will need to change the bucket_name on line 53 in mapproxy.yaml. 10 | 11 | Currently mapproxy.yaml is configured to hit the OSM tile server, you can configure the services, layers, caches, grids, and sources as per the documentation at (https://mapproxy.org). Note that this lambda is really only set up to use the S3 cache. 12 | 13 | To get started, you must have npm already installed on your system along with a couple plugins: 14 | ```sh 15 | npm install -g serverless 16 | serverless plugin install -n serverless-apigw-binary 17 | serverless plugin install -n serverless-wsgi 18 | ``` 19 | 20 | From here, you can deploy using serverless: 21 | ```sh 22 | serverless deploy 23 | ``` 24 | 25 | This command line will return information about what has been deployed. The most important bit here is the endpoints which will return a link like: 26 | ``` 27 | endpoints: 28 | GET - https://nobqrkpnhl.execute-api.us-west-1.amazonaws.com/dev/{proxy+} 29 | ``` 30 | Going to the link provided minus the {proxy+} will take you to the MapProxy Root (https://nobqrkpnhl.execute-api.us-west-1.amazonaws.com/dev/ will remain up through FOSS4GNA as an example) 31 | -------------------------------------------------------------------------------- /config.py: -------------------------------------------------------------------------------- 1 | # WSGI module for use with Apache mod_wsgi or gunicorn 2 | 3 | from mapproxy.wsgiapp import make_wsgi_app 4 | app = make_wsgi_app(r'mapproxy.yaml') 5 | -------------------------------------------------------------------------------- /mapproxy.yaml: -------------------------------------------------------------------------------- 1 | # ------------------------------- 2 | # MapProxy example configuration. 3 | # ------------------------------- 4 | # 5 | # This is a minimal MapProxy configuration. 6 | # See full_example.yaml and the documentation for more options. 7 | # 8 | 9 | # Starts the following services: 10 | # Demo: 11 | # http://localhost:8080/demo 12 | # WMS: 13 | # capabilities: http://localhost:8080/service?REQUEST=GetCapabilities 14 | # WMTS: 15 | # capabilities: http://localhost:8080/wmts/1.0.0/WMTSCapabilities.xml 16 | # first tile: http://localhost:8080/wmts/osm/webmercator/0/0/0.png 17 | # Tile service (compatible with OSM/etc.) 18 | # first tile: http://localhost:8080/tiles/osm/webmercator/0/0/0.png 19 | # TMS: 20 | # note: TMS is not compatible with OSM/Google Maps/etc. 21 | # fist tile: http://localhost:8080/tms/1.0.0/osm/webmercator/0/0/0.png 22 | # KML: 23 | # initial doc: http://localhost:8080/kml/osm/webmercator 24 | 25 | services: 26 | demo: 27 | tms: 28 | use_grid_names: true 29 | # origin for /tiles service 30 | origin: 'nw' 31 | kml: 32 | use_grid_names: true 33 | wmts: 34 | wms: 35 | md: 36 | title: MapProxy WMS Proxy 37 | abstract: This is a minimal MapProxy example. 38 | 39 | layers: 40 | - name: osm 41 | title: OpenStreetMap 42 | sources: [osm_cache] 43 | 44 | caches: 45 | osm_cache: 46 | grids: [webmercator] 47 | sources: [osm_wms] 48 | cache: 49 | type: s3 50 | directory: /tmp/osm_cache/ 51 | directory_layout: reverse_tms 52 | profile_name: demo 53 | bucket_name: mapproxy-lambda-demo 54 | 55 | sources: 56 | osm_wms: 57 | type: tile 58 | grid: webmercator 59 | url: http://tile.openstreetmap.org/%(z)s/%(x)s/%(y)s.png 60 | transparent: true 61 | grids: 62 | webmercator: 63 | base: GLOBAL_WEBMERCATOR 64 | 65 | globals: 66 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | MapProxy==1.11.0 2 | Pillow==6.0.0 3 | pkg-resources==0.0.0 4 | PyYAML>=4.2b1 5 | -------------------------------------------------------------------------------- /serverless.yml: -------------------------------------------------------------------------------- 1 | service: mapproxy 2 | provider: 3 | name: aws 4 | runtime: python3.6 5 | stage: dev 6 | region: us-west-1 7 | memorySize: 256 8 | timeout: 30 9 | iamRoleStatements: 10 | - Effect: "Allow" 11 | Action: 12 | - "s3:*" 13 | Resource: 14 | Fn::Join: 15 | - "" 16 | - - "arn:aws:s3:::mapproxy-lambda-demo*" 17 | environment: 18 | MAPPROXY_LIB_PATH: /var/task/lib:/var/task/mapproxy 19 | 20 | plugins: 21 | - serverless-wsgi 22 | - serverless-apigw-binary 23 | 24 | custom: 25 | wsgi: 26 | app: config.app 27 | apigwBinary: 28 | types: 29 | - '*/*' 30 | 31 | functions: 32 | app: 33 | handler: wsgi_handler.handler 34 | layers: 35 | - arn:aws:lambda:us-west-1:081097954549:layer:proj:9 36 | events: 37 | - http: 38 | path: /{proxy+} 39 | method: get 40 | cors: 41 | origin: '*' 42 | headers: 43 | - Content-Type 44 | - X-Amz-Date 45 | - Authorization 46 | - X-Api-Key 47 | - X-Amz-Security-Token 48 | - X-Amz-User-Agent 49 | allowCredentials: false 50 | - http: 51 | path: / 52 | method: get 53 | cors: 54 | origin: '*' 55 | headers: 56 | - Content-Type 57 | - X-Amz-Date 58 | - Authorization 59 | - X-Api-Key 60 | - X-Amz-Security-Token 61 | - X-Amz-User-Agent 62 | allowCredentials: false --------------------------------------------------------------------------------