title: Update user location with AWS dynamodb-geo and Lambda?
body: <p>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 <a href="https://github.com/awslabs/dynamodb-geo" rel="noreferrer">dynamodb-geo</a> library in a Lambda function.  </p>
  
  <p>I have a DynamoDB table that works with the dynamodb-geo library. It has the <em>geoHash</em> as a <em>hashKey</em>. For the <em>rangeKey</em> I use the <em>userId</em>. I can store the location of a user with <em>putPoint</em>:</p>
  
  <pre><code>GeoPoint geoPoint = new GeoPoint(latitude, longitude);
  AttributeValue rangeKeyAttributeValue = new AttributeValue().withS(“someUserId”);
  PutPointRequest putPointRequest = new PutPointRequest(geoPoint, rangeKeyAttributeValue);
  geoDataManager.putPoint(putPointRequest);
  </code></pre>
  
  <p>To find nearby users I use the <em>queryRadius</em> function:</p>
  
  <pre><code>GeoPoint currentPoint = new GeoPoint(latitude, longitude);
  QueryRadiusRequest request = new QueryRadiusRequest(currentPoint, radius);
  return geoDataManager.queryRadius(request).getItem();
  </code></pre>
  
  <p>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 <em>putPoint</em> or <em>updatePoint</em> functions. From the javadoc of <em>updatePoint</em>:</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>I understand why this is the case, it is how DynamoDB works. I can not update the <em>hashKey</em>. 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:</p>
  
  <p>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.</p>