AWS Builder Center
Routing around flooded lanes: A* on OpenStreetMap graphs inside AWS Lambda

Routing around flooded lanes: A* on OpenStreetMap graphs inside AWS Lambda

Normal navigation does not know a road is under water, and it knows nothing about inner lanes (galis), where many two-wheeler trips actually go. For "Can My Scooter Cross?" we built a small router that avoids flooded spots, per vehicle, and runs inside AWS Lambda.

Graphs as compact files in S3

We download each city's road network with OSMnx, remove private gated roads, parking aisles and driveways, and write a compact JSON graph (nodes, edges with length and road class). Each city is only about 0.4 to 0.7 MB compressed, stored in Amazon S3. The routing Lambda loads the graph once per cold start and keeps it in memory.

One trip, several vehicles

The router runs A* with costs that depend on the vehicle:
  • A spot that is NO-GO for your vehicle is blocked; RISKY costs extra.
  • Buses use only major roads (motorway to tertiary), so they never get sent down a lane.
  • Start and end points snap to the strongly connected part of each vehicle's network, so a route never starts on a one-way stub.
That is why the answer can read: scooter must detour (+2 min), car can take the usual road slowly, bus is fine. We compute the usual route and the safe route, then show both, and name the blocked spot and its depth.

Honest edge cases

If a point is outside the cities we cover, the API says so and lists the covered areas instead of returning a made-up route. "No reports" is not shown as "dry roads". And an opt-in predictive outlook compares routes using the hourly rain forecast and current reports, labelled as a prototype index rather than a probability.

The Lambda side

The route function is a normal Lambda behind API Gateway; it reads active flooded spots from DynamoDB by geohash cell for the trip's bounding box. We test the router on a tiny synthetic grid in  pytest  so the logic is verified without any AWS call, and the same code runs locally through a small mock API.

From route to your pocket

Once a route is ready it opens in Google Maps (passing points from our dry route as waypoints so Google follows it), and a built-in navigation mode gives turn-by-turn directions with a spoken warning before a flooded road.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article