Front-End Web & Mobile
Geo Library for Amazon DynamoDB – Part 2: GeoDataManagerConfiguration
In order to use Geo Library for Amazon DynamoDB, you need to go through some setup steps. GeoDataManagerConfiguration
represents the mandatory and optional configurations, and in this blog post, I’ll show you how to use GeoDataManagerConfiguration
to customize the behavior of Geo Library.
Instantiating GeoDataManager
GeoDataManager
is the main class you interact with when using Geo Library. In order to instantiate GeoDataManager
, you need to pass an instance of GeoDataManagerConfiguration
:
AWSCredentials credentials = new BasicAWSCredentials(YOUR_ACCESS_KEY, YOUR_SECRET_KEY); AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); ddb.setRegion(usWest2); GeoDataManagerConfiguration config = new GeoDataManagerConfiguration(ddb, "geo-test"); GeoDataManager geoIndexManager = new GeoDataManager(config);
In the above example, you are telling GeoDataManager
to use a DynamoDB table named geo-test
in the US West (Oregon) region.
NOTE: It is important to correctly set your region on AmazonDynamoDBClient
to where your table is. For the full list of regions, refer to Regions and Endpoints.
GeoDataManagerConfiguration
GeoDataManagerConfiguration
allows you to configure many aspects of GeoDataManager
:
Configurable Attribute | Required / Optional | Default |
---|---|---|
AmazonDynamoDBClient used to access the DynamoDB table |
Required | N/A |
Amazon DynamoDB table name | Required | N/A |
Attribute name of the hash key | Optional | hashKey |
Attribute name of the range key | Optional | rangeKey |
Attribute name of the Geohash | Optional | geohash |
Attribute name of the Geo Json | Optional | geoJson |
Index name on the Geohash attribute | Optional | geohash-index |
Length of hash key | Optional | 6 |
ExecutorService used to control threading |
Optional | Thread pool size of 10 |
Example
For instance, when you instantiate GeoDataManager
with the above code snippet, the library will work with the following DynamoDB table:
Table name: geo-test
hashKey (Hash key) | rangeKey (Range key) | geohash (Indexed: index name is geohash-index) | geoJson | …and your additional attributes | … |
---|---|---|---|---|---|
… | … | … | … | … | … |
If you want to customize it and use a different table called Schools,
Table name: Schools
schoolHashKey (Hash key) | schoolId (Range key) | schoolGeohash (Indexed: index name is school-geohash-index) | schoolGeoJson | …and your additional attributes | … |
---|---|---|---|---|---|
… | … | … | … | … | … |
you can instantiate GeoDataManager
as follows:
AWSCredentials credentials = new BasicAWSCredentials(YOUR_ACCESS_KEY, YOUR_SECRET_KEY); AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(credentials); Region usWest2 = Region.getRegion(Regions.US_WEST_2); ddb.setRegion(usWest2); GeoDataManagerConfiguration config = new GeoDataManagerConfiguration(ddb, "Schools") .withHashKeyAttributeName("schoolHashKey") .withRangeKeyAttributeName("schoolId") .withGeohashAttributeName("schoolGeohash") .withGeoJsonAttributeName("schoolGeoJson") .withGeohashIndexName("school-geohash-index"); GeoDataManager geoIndexManager = new GeoDataManager(config);
As always, please leave a comment below if you have questions.