New to DynamoDB.
I'm creating a table with Primary Key 'UserID', Composite Key 'DateTime' and then I have the following as a value (note: I don't need to query any specifics in the below data - just write and read it):
UserID1
UserID2
Message
DateTime
Questions:
You can store a JSON document as an attribute in a DynamoDB table. To do this, use the withJSON method of Item . This method parses the JSON document and maps each element to a native DynamoDB data type.
You can store them as an object in Amazon S3 and then store the object identifier in your DynamoDB item. You can also use the object metadata support in Amazon S3 to provide a link back to the parent item in DynamoDB. Store the primary key value of the item as Amazon S3 metadata of the object in Amazon S3.
DynamoDB uses JSON only as a transport protocol, not as a storage format. The AWS SDKs use JSON to send data to DynamoDB, and DynamoDB responds with JSON. DynamoDB does not store data persistently in JSON format. For more information about JSON, see Introducing JSON on the JSON.org website.
So your options are:
Hash Key | Range Key | Attributes
----------------------------------
user id | utc time | json data
----------------------------------
user123 | 1357306017 | {UserID1:0, UserID2:0, Message:"", DateTime:0}
or
Hash Key | Range Key | Attributes
--------------------------------------------------------------
user id | utc time | UserID1 | UserID2 | Message | DateTime
--------------------------------------------------------------
user123 | 1357306017 | 0 | 0 | "" | 0
Both are viable options, and the choice comes down to how you want to read the data, if you have an attribute for each item, then you can request those attributes individually.
We tend to use a hybrid approach based upon our usage patterns. Elements we need to access individually are given their own attributes. Elements that we only ever want to access along with a collection of other elements all get assigned a single attribute and are then stored as a single blob of JSON string or a base64 encoded data.
For part two, indeed, you are right, you don't need to store user id and date time again as part of the attributes because they are the hash and range keys, which are returned when you make a request.
With DynamoMapper you could do this in Java:
@DynamoDBTable(tableName = "myClass")
public class MyClass {
@DynamoDBHashKey(attributeName = "id")
private String id;
@DynamoDBRangeKey(attributeName = "rangeKey")
private long rangeKey;
@DynamoDBTypeConvertedJson
private Content content;
}
And the content class could be:
public class Content {
@JsonProperty
private List<Integer> integers = new ArrayList();
@JsonProperty
private List<String> strings = new ArrayList();
}
DynamoDB now supports json object direct storing. read: http://aws.amazon.com/blogs/aws/dynamodb-update-json-and-more/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With