4

Need help with DynamoDB.

I am switching back end from Parse.com (because they are retiring parse) to AWS mobile hub.

I want to capture and save the date and time for which a row or item of data is written into my dynamodb table. In parse it is done automatically but not so in dynamodb.

I have searched around on the internet for clues but no solid explanation or example at the moment.

Can someone please point me in the right direction or pls show an example code here on how to implement CreatedAt and UpdatedAt into dynamodb.

Do I get my system time and save it to dynamodb or get server time?

If I need to get server timestamp which AWS server time do I get and how can I implement it?

Thanks a lot.

Chen Harel
  • 9,684
  • 5
  • 44
  • 58
S bruce
  • 1,514
  • 3
  • 16
  • 24

3 Answers3

1

AWS enables one to Use AWS Lambda with Amazon DynamoDB

This enables you to trigger server-side code based on DynamoDB events. It's way more involved than Parse but would enable you to avoid using app-side dates/times/code to maintain CreatedAt and UpdatedAt values.

Such datetime values need to be Ints or Strings as Datetime is not a JSON type and DynamoDB doesn't go beyond basic JSON field types.

Carl
  • 2,896
  • 2
  • 32
  • 50
0

This is tricky for a number of reasons. First if you require strict order of events, then using time can cause a bunch of errors and you might want to look into more advanced distributed systems algorithms like https://en.wikipedia.org/wiki/Lamport_timestamps or https://en.wikipedia.org/wiki/Vector_clock.

If just 'pretty close' is fine for your use case then the main thing you need to keep in mind is that mobile device system time is often incorrect. User's can change the clock, move between time zones, ect... There are a few things you could do.

A) You could have your own server that keeps a central time that you ping B) Dynamo also returns a date header when you make calls which you could look, but it's returned in the response. However you could at least use it to see if the date on your device is accurate. The SDK some something similar if you see https://github.com/aws/aws-sdk-android/blob/78cdf680115a891a6e1355c56068e2f56e3c5056/aws-android-sdk-core/src/main/java/com/amazonaws/http/AmazonHttpClient.java when Dynamo returns an error if the date in the signature from the request doesn't match the time Dynamo is expecting. This probably isn't the best solution, but should at least give you ideas of possible avenues.

WestonE
  • 682
  • 3
  • 7
  • Thank you for your response. It gives more hack options for me to consider. I'll look into them and share my solution here. – S bruce Feb 16 '16 at 11:28
0

I have decided to capture System.currentTimeMillis() at the time a user clicks the post/save button on my app and save the Epoch time in milliseconds into my DB CreatedAT attribute. I read here : "One of the most important things to realize is that 2 persons calling System.currentTimeMillis() at the same time should get the same result no matter where they are one the planet" So I intend to generate a random UUID Primary Key (Hash Key) and then save the user's CreatedAT time as the Sort Key.

I am open to any other practical options. I will use this in the mean time for testing and observe the behaviour.

S bruce
  • 1,514
  • 3
  • 16
  • 24