Database Reference
In-Depth Information
The following code will update a table with the passed UpdateTableRequest in-
stance:
client.updateTable(updateTableRequest);
The default location of the credential file is $USER_HOME/.aws/credentials . But
we have to keep our credentials file at $USER_HOME/.aws/config so that the SDK
easily identifies them. In the following code:
• The first line of the try block will load the default AWS credentials
• The second line will configure the DynamoDB client with the loaded credential
• The third line will initialize the region to US_WEST_2 , which is Oregon
• The last line of the try block will set the region for the DynamoDB client to
US-WEST-2
In the event of the improper location of the credentials file, an exception will be thrown as
follows:
private static void initializeCredentials() throws
Exception {
AWSCredentials credentials = null;
try {
credentials = new
ProfileCredentialsProvider().getCredentials();
client = new AmazonDynamoDBClient(credentials);
Region usWest2 = Region.getRegion(Regions.US_WEST_2);
client.setRegion(usWest2);
} catch (Exception e) {
throw new AmazonClientException(
"Invalid location or format of credentials file.",e);
}
}
The following function will prepare an ArrayList , which adds all the Attrib-
uteDefinition instances to it. Each AttributeDefinition will take two para-
meters: the first is the attribute name and the second is its attribute type, as shown in the
following code. In the following code, we are defining five attributes:
private static ArrayList<AttributeDefinition>
getTableAttributes() {
Search WWH ::




Custom Search