AWS Architecture Blog
Optimizing fleet utilization with Amazon Location Service and HERE Technologies
The fleet management market is expected to grow at a Compound Annual Growth Rate (CAGR) of 15.5 percent—from 25.5 billion US dollars in 2022 to USD 52.4 billion in 2027. Optimizing how your organization uses its vehicle fleet is important for logistics and service providers such as last mile, middle mile, and field services.
In this post, we demonstrate how to build and run a solution for many-to-many vehicle routing using HERE Tour Planning and Amazon Location Service. HERE Technologies is a data provider for Amazon Location Service and provides it with map rendering, geocoding, search, and routing. HERE Tour Planning expands on functionality such as geocoding, basic routing, and matrix routing to consider parameters such as time windows, job requirements or priorities, vehicle capabilities, range, and traffic information. They also support immediate re-planning when conditions change.
The architecture described in this post can help you optimize your fleets for delivering shipments, such as perishable items on pallets, from a central distribution center to multiple retail locations. The architecture uses the AWS Cloud Development Kit (AWS CDK) to help you provision and version control your infrastructure. The architecture also uses Event Driven Architecture (EDA) based on AWS Lambda and Amazon DynamoDB. It uses Amazon Simple Storage Service (Amazon S3) and DynamoDB to store the artifacts generated and integrates with Amazon Location Service to plot the routes visually on a map for each delivery driver.
Solution overview
This post will help you:
- Configure the many-to-many vehicle routing architecture using HERE Tour Planning and Amazon Location Service
- Submit a HERE Tour Planning problem
- Generate an optimized solution file
- Run a React app that:
- Generates a list of routes for each vehicle in the fleet
- Allows drivers to select and view routes in detail
The following diagram outlines how the architecture works.
Let’s explore the steps in the diagram.
- The fleet operator uploads the tour requirements file to an Amazon S3 bucket.
- The upload invokes a Lambda function to process the new Tour Request. If the HERE API key is present, it calls the HERE Tour Planning API.
- The HERE Tour Planning API calculates the solution to the routing problem.
- The driver uses the React app to select a vehicle, which requests a route.
- The invoked Lambda function uses Amazon Location Service to calculate the route and render it in the React app.
Prerequisites
This walkthrough requires the following installations and resources:
- Have an AWS account
- Install the AWS Amplify CLI (command-line interface)
- Install the AWS CDK CLI
- Install the AWS CLI
- Configure and authenticate the AWS CLI to interact with your AWS account.
- Have your preferred integrated development environment (IDE), such as Visual Studio Code
- Have GitHub repository access
git clone https://github.com/aws-samples/aws-here-optimize-fleet-utilization
- Have a HERE API Key (optional)
- This is needed to invoke the HERE Tour Planning API for generating solutions to new routing problems.
- The GitHub sample repository includes a problem and pre-solved solution file, so you don’t need to acquire a HERE API key to learn about these offerings.
- To acquire an API key, create a free account on the HERE Platform, then follow the instructions in the HERE Tour Planning documentation to create your API key.
- There can be additional charges based on API key use. For more details, see the HERE Tour Planning section within HERE service rates.
Walkthrough
Provision the infrastructure
- The architecture uses NPM node modules. Run the following commands to install the dependencies:
# AWS Lambda function dependencies
cd lib/lambda/calculate-route
npm install
# Sample Frontend application dependencies
cd frontend/here-driver-app
npm install
- If you have never used AWS CDK in your AWS account, you must first bootstrap the solution, which creates Amazon S3 buckets and metadata to support AWS CDK operations. Note: Architectural components described in this article are covered under AWS Free Tier and HERE Free monthly usage, but additional charges can occur based on usage beyond the Free Tier limits. We recommend following the Cleanup instructions after completing the walkthrough.
-
- From the root of the repository, run the following command to generate the needed infrastructure:
cdk bootstrap
- Output similar to the following indicates that you successfully bootstrapped the AWS account with what AWS CDK requires.
- From the root of the repository, run the following command to generate the needed infrastructure:
-
- Deploy the infrastructure for this solution by running the following command. This provisions much of the infrastructure required for this solution such as DynamoDB, Lambda functions, and Amazon S3 buckets:
cdk deploy
- Next, Amplify provisions the remaining resources to complete the architecture. Navigate to the folder for the frontend by running the following command:
cd frontend/here-driver-app
- Run the following series of Amplify commands to create the remaining resources, Amazon API Gateway, Amazon Cognito, and Amazon Location Service. For additional details, see Clone sample Amplify project.
- To accept the defaults, run the following command:
amplify init
- To push the infrastructure out to the AWS account, run the following command:
amplify push
- To publish the environment, run the following command:
amplify publish
Create problem and generate architecture files
The next step is to create the HERE Tour Planning problem file and submit it to the HERE Tour Planning API to solve. Note: You can either sign up for the HERE Developer program to receive an API key to test this solution live or use the problem and pre-solved solution provided in the /data
folder of the repository.
- Open the Amazon S3 bucket that the previous step created.
- Upload a problem file (in JSON format) to the bucket.
- An Amazon S3 event notification invokes a Lambda function that performs a synchronous call to the HERE Tour Planning API and generates vehicle routing problem solution file in JSON format.
- The Lambda function saves the solution file to the Amazon S3 bucket and additional details about the solution to a DynamoDB table.
- The delivery drivers can use the example React app to view the list of vehicles and the routes.
Frontend
The next step is to run the React Frontend app to see the results. Access to the app and the API Gateway is secured with Amazon Cognito.
- To run the web application, run the following command:
npm start
- A local web server runs on http://localhost:3000.
- To use the system, the user must authenticate. Amazon Cognito allows users to sign in or create a new account.
- After you authenticate, the Home screen displays a list of available vehicles and routes.
Choose a vehicle to see the detail of the route. Each red marker is a stop.
Cleanup
To avoid incurring future charges, delete all resources created.
- Run the following commands to delete the application in AWS Amplify. As an alternative, you can use the Amplify console to delete Amplify resources:
cd frontend/here-driver-app
amplify pull
amplify delete
- With AWS CDK, run the following command to delete the AWS CloudFormation stack that was used to provision the resources. Note: You can leave the AWS CLI, Amplify CLI, and CDK CLI installed on your computer for future development:
cdk destroy
Conclusion
In this post, using shipment delivery from a central distribution center use case, we’ve demonstrated how you can build your own serverless solution for optimizing middle and last mile operations. The solution uses multi-vehicle and multi-stop optimization services provided by HERE Tour Planning and Amazon Location Service to visualize the generated routes for each delivery vehicle driver. For additional details about HERE’s offerings on AWS Marketplace, see AWS Marketplace: HERE Technologies.