DynamoDB にはローカルで実行できるツールが配布されています。
http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest
より最新版の DynamoDB Local をダウンロードします。
起動方法は、
java -Djava.library.path=. -jar DynamoDBLocal.jar --port 8088
Java SDK でアクセスする場合は、以下のようにエンドポイントを切り替えて利用します。
String accessKey = "********************************";
String secretKey = "********************************";
AmazonDynamoDB client =
new AmazonDynamoDBClient(new BasicAWSCredentials(accessKey, secretKey));
// エンドポイントの設定
client.setEndpoint("http://localhost:8088");
// テーブル作成
List<KeySchemaElement> elements = new ArrayList<KeySchemaElement>();
elements.add(new KeySchemaElement().withAttributeName("id").withKeyType(
KeyType.HASH));
AttributeDefinition def =
new AttributeDefinition().withAttributeName("id").withAttributeType(
ScalarAttributeType.S);
ProvisionedThroughput pt =
new ProvisionedThroughput()
.withReadCapacityUnits(10L)
.withWriteCapacityUnits(5L);
client.createTable(new CreateTableRequest("test", elements)
.withAttributeDefinitions(def)
.withProvisionedThroughput(pt));
// データ登録
Map<String, AttributeValue> map = new HashMap<String, AttributeValue>();
map.put("id", new AttributeValue("1"));
client.putItem(new PutItemRequest("test", map));
// データ取得
GetItemResult item = client.getItem(new GetItemRequest("test", map));
Map<String, AttributeValue> result = item.getItem();

