This project provides AWS Lambda as proxy for HERE Traffic API. This AWS Lambda is packaged as per the AWS Serverless Application Model.
"AWS SAR is natively supported by AWS CloudFormation and defines simplified syntax for expressing serverless resources. The specification currently covers APIs, Lambda functions and Amazon DynamoDB tables."
The AWS API Gateway supports configuring both Cache and Throttling, and the lambdas are open source: we welcome pull requests with circuit breakers, graceful error handling, etc.!
To successfully call the HERE Traffic API through the proxy in this project, you need to obtain HERE API credentials. Multiple plans are available: https://aws.amazon.com/marketplace/pp/B07JPLG9SR/?ref=_ptnr_aws_sar_github#pricing-information.
Visit the HERE Location Services on AWS Marketplace, and review the Access Control FAQ.
Visit AWS and sign up for a Free Tier account.
Download and install the AWS CLI, and run aws configure as per the AWS CLI User Guide.
From GitHub: clone this repository, or download the ZIP.
The folder containing the lambda source code (JS) and CloudFormation templates (YML) is serverlessFunctions\traffic\.
An S3 bucket is required as a destination for the AWS SAR package. If you don't have one already, create one:
aws s3 mb s3://here-maps-api--aws-sar
Note: If the folder contains a package.json file: run npm update:
x:\src\here-aws-repository\serverlessFunctions\traffic>npm update
Use the AWS CLI to package (note the folder layout):
x:\src\here-aws-repository\serverlessFunctions>aws cloudformation package --s3-bucket here-maps-api--aws-sar --template-file traffic\traffic.yml --output-template-file traffic-packaged.yml
Use the AWS CLI to deploy the AWS SAR package using CloudFormation:
x:\src\here-aws-repository\serverlessFunctions>aws cloudformation deploy --capabilities CAPABILITY_IAM --stack-name "HERE-Maps-API--Traffic" --parameter-overrides HereApiKey=<apiKey> --template-file traffic-packaged.yml
Once deployment completes, look for the URL of the new API Gateway. It should follow this pattern:
https://<apigw>.execute-api.<region>.amazonaws.com/...
The API Gateway URL is an output from the CloudFormation template and can be found among the tabs when selecting a Stack in the AWS Console.
Alternatively look at the API Gateway in the AWS Console, select Stages, and then expand the tree until you see "Invoke URL".
Note: The AWS Lambda proxy deployed above do not impose authentication or authorization restrictions!
You must decide how you will control access to your API Gateway and Lambda.
For guidance, see the AWS Lambda FAQ.
Consider implementing AWS API Gateway Custom Authorizers.
URL Mapping
| API | HERE URL Prefix | AWS Lambda App URL Prefix |
|---|---|---|
| Traffic | https://traffic.ls.hereapi.com/ |
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/traffic/api/traffic/ |
| Traffic(tiles) | https://{1..4}.traffic.maps.ls.hereapi.com/ |
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/traffic/api/traffic.maps/ |
-
An example of an HTTP GET request to HERE Traffic API & equivalent AWS Lambda Proxy:
HERE Traffic API:
https://traffic.ls.hereapi.com/traffic/6.3/incidents/json/8/218/99?apiKey=<apiKey> -
To call the Lambda proxy instead, replace the original URL with the API Gateway URL, change the type, resourcePath and Query String Parameters as follows:
Equivalent AWS Lambda Proxy for HERE Traffic API:
API Gateway URL format:
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/traffic/api/{type}/{resourcePath+}{type}:
traffic{resourcePath+}:
traffic/6.3/incidents/json/8/218/99API Gateway URL:
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/traffic/api/traffic/traffic/6.3/incidents/json/8/218/99 -
An example of an HTTP GET request to HERE Traffic(tiles) API & equivalent AWS Lambda Proxy:
HERE Traffic(tiles) API:
https://1.traffic.maps.ls.hereapi.com/traffic/6.0/tiles/8/133/86/256/png32?apiKey=<apiKey> -
To call the Lambda proxy instead, replace the original URL with the API Gateway URL, change the type, resourcePath and Query String Parameters as follows:
Equivalent AWS Lambda Proxy for HERE Traffic(tiles) API:
API Gateway URL format:
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/traffic/api/{type}/{resourcePath+}{type}:
traffic.maps{resourcePath+}:
traffic/6.0/tiles/8/133/86/256/png32API Gateway URL:
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/traffic/api/traffic.maps/traffic/6.0/tiles/8/133/86/256/png32
The AWS Lambda Proxy URL depends on the base URL type. For example:
-
https://1.traffic.maps.ls.hereapi.com/traffic/6.0/tiles/8/133/86/256/png32
Base URL: traffic.maps
Lambda Proxy URL: /traffic/api/traffic.maps/
-
https://traffic.ls.hereapi.com/traffic/6.0/incidents.json
Base URL: traffic
Lambda Proxy URL: /traffic/api/traffic/
For details document please refer HERE Traffic API
Copyright (c) 2017-2019 HERE Europe B.V.
See the LICENSE file in the root of this project for license details.