I am developing an iOS app that displays nearby app users. When a user’s location changes it is send to the server. The app is polling the server once every few minutes to discover currently nearby users. I was using Parse, this worked well. Now I want to replace the Parse backend by AWS services. My idea is to deploy the dynamodb-geo library in a Lambda function.
I have a DynamoDB table that works with the dynamodb-geo library. It has the geoHash as a hashKey. For the rangeKey I use the userId. I can store the location of a user with putPoint:
GeoPoint geoPoint = new GeoPoint(latitude, longitude);
AttributeValue rangeKeyAttributeValue = new AttributeValue().withS(“someUserId”);
PutPointRequest putPointRequest = new PutPointRequest(geoPoint, rangeKeyAttributeValue);
geoDataManager.putPoint(putPointRequest);
To find nearby users I use the queryRadius function:
GeoPoint currentPoint = new GeoPoint(latitude, longitude);
QueryRadiusRequest request = new QueryRadiusRequest(currentPoint, radius);
return geoDataManager.queryRadius(request).getItem();
So far, so good. Now to the problem. An existing user has moved somewhere else and his new location is sent to the server. How do I update his location? I can not use the putPoint or updatePoint functions. From the javadoc of updatePoint:
Update a point data in Amazon DynamoDB table. You cannot update attributes specified in GeoDataManagerConfiguration: hash key, range key, geohash and geoJson. If you want to update these columns, you need to insert a new record and delete the old record.
I understand why this is the case, it is how DynamoDB works. I can not update the hashKey. I have to delete the old item and add the new one. This additional processing raises some doubts about my plan to use dynamodb-geo with Lambda:
I would like to know if my proposed solution using dynamodb-geo with Lambda is a good and scalable approach to implement my use case. I am pretty new to AWS, I am always interested in suggestions for better alternatives.