AWS Location Service: Where my AWS Community Builders at?
Tags: aws, maps, geo, community
Published: 2021-06-11 20:46:06

**TLDR;** I built a map of AWS Community Builders using AWS Location Services.  [Click here for the map](https://acbmap.humbleg.com/aws/), [click here for the code](https://github.com/jdonboch/acbmap-aws).

----

I was recently accepted into the [AWS Community Builders program](https://aws.amazon.com/developer/community/community-builders/) and have been blown away by how geographically diverse the group is.  The program is split up into different technology-based cohorts--although this is very loose coupling and members are free to join discussions and sessions for any set of technology they are interested in--but there is no location based grouping.  

This led to many asking the same question: are there any other AWS Community Builders near me?

The manager of the program, [Jason Dunn](https://twitter.com/jasondunn), agreed to share some anonymized location data with me and I volunteered to draft a quick proof-of-concept map that would display the locations.  

I initially implemented this via [Google Maps JS API](https://developers.google.com/maps/documentation/javascript/overview) ([code can be found here](https://github.com/jdonboch/acbmap)) but with the [release of AWS Location Service](https://aws.amazon.com/blogs/aws/amazon-location-service-is-now-generally-available-with-new-routing-and-satellite-imagery-capabilities/), I decided it was worth trying to experiment with this new service.

## What is Amazon Location Service?

[Amazon Location Service](https://aws.amazon.com/location/) is a new set of resources to support maps and location-based use cases such as geocoding, routing, asset/device tracking and geo-fence events.

As of the writing of this, the AWS Location Service has been GA for less than 2 weeks.  I look forward to new features and integrations that will inevitably come in the future as the service continues to get some exercise.

### Initial Impressions (of Maps and Geocoding)

Here are my initial impressions.  I have only really experimented with maps and geocoding to support this simple use case.  

The routing, tracking and geofencing components look very interesting but I don't have any direct experience with them yet.

#### Good: Great integration with other AWS Services 
If you are already in the AWS eco-system, using Amazon Location Services will be very easy as you can continue to use the tools and SDKs you are already using.  You can control access and security via IAM, automate deployments via CloudFormation, monitor with CloudWatch, be notified of location-based events via Amazon EventBridge, etc.
#### Good: Creates an abstraction for various location providers. 
Amazon currently supports its clients using [Esri](https://www.esri.com/en-us/home) or [HERE](https://www.here.com/) data sets and services.  When you create Amazon resources for maps, places, etc you choose which provider you want to supply the data.  Each provider has their own strengths and weakness but you can now switch easily without needing to integrate with each unique location provider API.  As new providers are added, you can continue to leverage the same interface.
#### Good: Better privacy and security
AWS does not have rights to sell your data or use it for advertising purposes (can Google say that?).  They also anonymize all your requests before submitting them to vendors.  Any tracking and geofence data is stored only in your AWS account (not 3rd parties) which gives you the power to control and secure that information.
#### Not so good: Free Tier/Pricing
AWS offers a free tier but it is only a 3-month trial.  After 3 months, you are on the hook for your requests based usage.  [Google Maps free-tier equivalent](https://cloud.google.com/maps-platform/pricing) (free mobile usage and $200 maps credit each month) does not expire and is much more generous.  The maps and geocoding prices are competitive with other services but Amazon charges on a per-tile basis when many other providers charge on a per map-load basis.  This means if your users are zooming and panning frequently, you will likely be paying more for Amazon Location Services.

This pricing makes Amazon Location Services a little less desirable for individuals, small prototyping efforts, and mobile map applications that are extremely price sensitive as you'll probably end up paying when other providers (i.e. Google) you can do a lot more with their free tier.

I hope that Amazon creates a more permanent free-tier for the mapping service at least.

~~#### Not so good: Lacking access controls for anonymous access to public maps.
Amazon Location Services provides an API that can be connected to other map libraries (i.e. [MapLibre](https://github.com/maplibre/maplibre-gl-js) and [Tangram](https://github.com/tangrams/tangram)).  This is sort of nice but it requires you to use a Cognito Identity Pool with anonymous access enabled if you want to display on a public website.  This is well documented in their [developer guide](https://docs.aws.amazon.com/location/latest/developerguide/amazon-location-developer-guide.pdf.pdf) but I feel like there are some access-controls lacking as there is no way to lock down your anonymous credentials to a particular IP or HTTP referrer like you can do with Google's API Keys.  This means someone could grab the Cognito Identity Pool ID from the Javascript source code in the browser and use it for their own map requests.  This seems like a big flaw and hoping some additional Conditional support could be added to IAM policies to better control anonymous access.~~ Someone pointed me in the right direction here and this is possible: [check out my article here on how to lock down AWS Location Service by referer or IP, similar to Google Maps API keys.](https://dev.to/jdonboch/restricting-unauthenticated-aws-access-by-referer-and-ip-similar-to-google-api-keys-1118)

## Creating the map and geocoding the data

To complete this proof of concept, I needed the following:

Given a list of locations, I needed to 1) geocode the locations to get their latitudes and longitudes and then 2) create a static map webpage to display the locations as markers on a map.  Bonus points if we can add some metadata on the markers.

### The map
There was not much innovation for the map part of the project and just a quick proof of concept was the goal.  It was accomplished by walking through the [following sections of the AWS Location Service Developer Guide](https://docs.aws.amazon.com/location/latest/developerguide/amazon-location-developer-guide.pdf.pdf) which is a great resource to get started! :
* Page 27: [Allowing unauthenticated guest access to your
application using Amazon Cognito](https://docs.aws.amazon.com/location/latest/developerguide/authenticating-using-cognito.html)
* Page 33: [Creating a Map Resource](https://docs.aws.amazon.com/location/latest/developerguide/maps-prerequisites.html#create-map-resource)
* Page 34: [Authenticating your requests](https://docs.aws.amazon.com/location/latest/developerguide/maps-prerequisites.html#tutorial-mapbox-identity-pool)
* Page 35: [Using MapLibre GL JS with Amazon Location Service](https://docs.aws.amazon.com/location/latest/developerguide/tutorial-maplibre-gl-js.html)

I also used some MapLibre tutorials below to help create the markers, icons and pop ups on the map:
* [Add icon to map](https://maplibre.org/maplibre-gl-js-docs/example/add-image/)
* [Create and style clusters (stole the pop up code here)](https://maplibre.org/maplibre-gl-js-docs/example/cluster/)

### The geocoding process
We need to [create a Place Index resource](https://docs.aws.amazon.com/location/latest/developerguide/places-prerequisites.html#create-place-index-resource) to support the geocoding.

To do the geocoding and create the GeoJSON that is displayed by the map, I wrote a quick Python script to perform that. This was fairly easy since the geocoding actions have been added to boto3 (i.e. the Python AWS SDK).  

Unfortunately, the only location information that we had for Amazon Community Builders was Country.  This resulted in many  duplicate markers being generated which the mapping library was not happy about.  In the end, I adjusted the logic of the geocoding script to create a single point for each country but then add properties to the point that indicated the number of people in that country.  This member count property could then be displayed as a pop up on the map when the user hovered over the map marker.

## Final Results

To see the final code and the geocoding script, [check out the acbmap-aws repo on GitHub](https://github.com/jdonboch/acbmap-aws).  I tried to add more details to that README with the specifics if you want to try and run this locally.

You can find the a hosted version of the AWS Community Builders map, powered by Amazon Location Services, at the following location:

https://acbmap.humbleg.com/aws/