あなたは単にあなたがテーブルを記述する際keySchemas
とattributeDefinitions
に反復する必要があります。
DynamodbTable
説明は構造、(私はclojure-awsを使用しています、あなたがテーブル構造を確認するためにaws cliを使用することができます)あなたが反復する必要がありますkey-schema
とattribute-definitions
キーを見ることができます
user=> (db/describe-table {:profile "aws-profile" :endpoint "us-west-2"} "KeyValueLookupTable1")
{:table {:key-schema [{:key-type "HASH", :attribute-name "leaseKey"}], :table-size-bytes 201, :attribute-definitions [{:attribute-name "leaseKey", :attribute-type "S"}], :creation-date-time #object[org.joda.time.DateTime 0x4c6ece3 "2017-06-07T15:50:35.057-07:00"], :item-count 1, :table-status "ACTIVE", :table-name "KeyValueLookupTable1", :provisioned-throughput {:read-capacity-units 10, :write-capacity-units 10, :number-of-decreases-today 0}, :table-arn "arn:aws:dynamodb:us-west-2:033814027302:table/KeyValueLookupTable1"}}
を以下ましたに。
1)HASH
とRANGE
キーを取得するためにTableDescription#getKeySchema
のドキュメントを参照してください。
例java8他のフィールドについて
DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient())
String getHashKeyAttributeName(String tableName) {
TableDescription tableSchema = dynamoDB.getTable(tableName).describe();
return tableSchema.getKeySchema().stream()
.filter(x -> x.getKeyType().equals(KeyType.HASH.toString()))
.findFirst().get().getAttributeName();
}
String getSortkeyAttributeName(String tableName) {
TableDescription tableSchema = dynamoDB.getTable(tableName).describe();
return tableSchema.getKeySchema().stream()
.filter(x -> x.getKeyType().equals(KeyType.RANGE.toString()))
.findFirst().get().getAttributeName();
}
2)で、あなたはtableDescription.getAttributeDefinitions
List<String> getOtherAttributeList(String tableName) {
DynamoDB dynamoDB = new DynamoDB(new AmazonDynamoDBClient());
TableDescription tableSchema = dynamoDB.getTable(tableName).describe();
return tableSchema.getAttributeDefinitions().stream()
.map(AttributeDefinition::getAttributeName)
.collect(Collectors.toList());
}
に乗った
List<AttributeDefinitions>
に反復処理する必要があります