Created
October 22, 2014 12:38
-
-
Save SaschaMoellering/fee91935075cc93e98c2 to your computer and use it in GitHub Desktop.
DynamoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.zanox.kinesis.dynamo; | |
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; | |
import com.amazonaws.regions.Region; | |
import com.amazonaws.regions.Regions; | |
import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; | |
import com.amazonaws.services.dynamodbv2.datamodeling.*; | |
/** | |
* Created by sascha.moellering on 17/10/2014. | |
*/ | |
@DynamoDBTable(tableName="KinesisData") | |
public class DynamoDBBean { | |
private String id; | |
private String payload; | |
@DynamoDBHashKey(attributeName = "Id") | |
@DynamoDBAutoGeneratedKey | |
public String getId() { return id; } | |
public void setId(String id) { this.id = id; } | |
@DynamoDBAttribute(attributeName="payload") | |
public String getPayload() { return this.payload; }; | |
public void setPayload(String payload) { this.payload = payload; }; | |
public static void saveItem(final String payload) { | |
AmazonDynamoDBClient dynamoDBClient = new AmazonDynamoDBClient(new DefaultAWSCredentialsProviderChain()); | |
dynamoDBClient.setRegion(Region.getRegion(Regions.EU_WEST_1)); | |
DynamoDBBean obj = new DynamoDBBean(); | |
obj.setPayload(payload); | |
// id field is null at this point | |
DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBClient); | |
mapper.save(obj); | |
System.out.println("Object was saved with id " + obj.getId()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment