This project provides AWS Lambda as proxy for Public Transit v8 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 Public Transit v8 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\transit\
.
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\transit>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 transit\transit.yml --output-template-file transit-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--Transit" --parameter-overrides HereApiKey=<apiKey> --template-file transit-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 |
---|---|---|
Next Departures | https:/transit.hereapi.com/ |
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/transit/api/ |
Station Search | https:/transit.hereapi.com/ |
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/transit/api/ |
Routing | https:/transit.router.hereapi.com/ |
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/transit/api/ |
An example of an HTTP GET request to HERE Public Transit API v8 & equivalent AWS Lambda Proxy:
Next Departures HTTP and Proxy URL
-
An example of an HTTP GET request to HERE Next Departures API & equivalent AWS Lambda Proxy:
HERE Next Departures API:
https:/transit.hereapi.com/v8/departures?apiKey=<apiKey>&ids=415712992
-
To call the Lambda proxy instead, replace the original URL with the API Gateway URL, change resourcePath and Query String Parameters as follows:
Equivalent AWS Lambda Proxy for Next Departures:
API Gateway URL format:
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/transit/api/{type}/{resourcePath+}
{type}:
transit
{resourcePath+}:
v8/departures?ids=415712992
API Gateway URL:
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/transit/api/transit/v8/departures?ids=415712992`
Station Search HTTP and Proxy URL
-
An example of an HTTP GET request to HERE Station Search API & equivalent AWS Lambda Proxy:
HERE Station Search API:
https:/transit.hereapi.com/v8/stations?apiKey=<apiKey>&in=41.90123,12.500912
-
To call the Lambda proxy instead, replace the original URL with the API Gateway URL, change resourcePath and Query String Parameters as follows:
Equivalent AWS Lambda Proxy for HERE Station Search:
API Gateway URL format:
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/transit/api/{type}/{resourcePath+}
{type}:
transit
{resourcePath+}:
v8/stations?in=41.90123,12.50091
API Gateway URL:
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/transit/api/transit/v8/stations?in=41.90123,12.50091
Routing HTTP and Proxy URL
-
An example of an HTTP GET request to HERE Transit Routing API equivalent AWS Lambda Proxy:
HERE Transit Routing API:
https://transit.router.hereapi.com/v8/routes?apiKey=<apiKey>&ids=415712992
-
To call the Lambda proxy instead, replace the original URL with the API Gateway URL, change resourcePath and Query String Parameters as follows:
Equivalent AWS Lambda Proxy for HERE Transit Routing API:
API Gateway URL format:
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/transit/api/{type}/{resourcePath+}
{type}:
transit.router
{resourcePath+}:
v8/routes?origin=41.79457,12.25473&destination=1.90096,12.50243
API Gateway URL:
https://<apigw>.execute-api.<region>.amazonaws.com/Prod/transit/api/transit.router/v8/routes?origin=41.79457,12.25473&destination=1.90096,12.50243`
For details document please refer Public Transit v8 API
Copyright (c) 2017-2019 HERE Europe B.V.
See the LICENSE file in the root of this project for license details.