Update user location with AWAM dynamodb-geo and Lambda?

I am developing an iOS application that displays neighboring users of the application. When changing the location of users, it is sent to the server. The application checks the server every few minutes to find nearby users. I used Parse, it worked well. Now I want to replace the Parse server with 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 geoHash as hashKey. For the Key range, I use userId. I can save the user's location using putPoint:

GeoPoint geoPoint = new GeoPoint(latitude, longitude); AttributeValue rangeKeyAttributeValue = new AttributeValue().withS("someUserId"); PutPointRequest putPointRequest = new PutPointRequest(geoPoint, rangeKeyAttributeValue); geoDataManager.putPoint(putPointRequest); 

To find the closest 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 to another location and his new location has been sent to the server. How to update its location? I cannot use putPoint or updatePoint functions. From javadoc updatePoint:

Update point data in an Amazon DynamoDB table. You cannot update the attributes specified in the 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 way DynamoDB works. I cannot update hashKey. I need to remove the old item and add a 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 for implementing my use case. I am new to AWS, I am always interested in suggestions for better alternatives.

+5
source share

Source: https://habr.com/ru/post/1245549/


All Articles