software.amazon.awssdk.services.dynamodb.model.DynamoDbException Java Examples
The following examples show how to use
software.amazon.awssdk.services.dynamodb.model.DynamoDbException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DynamoDBMappingGetItem.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static String getItem(DynamoDbEnhancedClient enhancedClient) { try { // Create a DynamoDbTable object DynamoDbTable<Record> mappedTable = enhancedClient.table("Record", TABLE_SCHEMA); // Create a KEY object Key key = Key.builder() .partitionValue("id-value") .sortValue("sort-value") .build(); // Get the item by using the key Record result = mappedTable.getItem(r->r.key(key)); return "The record id is "+result.getId(); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.enhanced_getitem.main] return ""; }
Example #2
Source File: DynamoDBScanItems.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void scanItems( DynamoDbClient ddb,String tableName ) { try { ScanRequest scanRequest = ScanRequest.builder() .tableName(tableName) .build(); ScanResponse response = ddb.scan(scanRequest); for (Map<String, AttributeValue> item : response.items()) { Set<String> keys = item.keySet(); for (String key : keys) { System.out.println ("The key name is "+key +"\n" ); System.out.println("The value is "+item.get(key).s()); } } } catch (DynamoDbException e) { e.printStackTrace(); } // snippet-end:[dynamodb.java2.dynamoDB_scan.main] }
Example #3
Source File: DeleteTable.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void deleteDynamoDBTable(DynamoDbClient ddb, String tableName) { DeleteTableRequest request = DeleteTableRequest.builder() .tableName(tableName) .build(); try { ddb.deleteTable(request); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.delete_table.main] System.out.println(tableName +" was successfully deleted!"); }
Example #4
Source File: EnhancedGetItem.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static String getItem(DynamoDbEnhancedClient enhancedClient) { try { // Create a DynamoDbTable object DynamoDbTable<Customer> mappedTable = enhancedClient.table("Customer", TableSchema.fromBean(Customer.class)); // Create a KEY object Key key = Key.builder() .partitionValue("id110") .build(); // Get the item by using the key Customer result = mappedTable.getItem(r->r.key(key)); return "The record id is "+result.getId(); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.mapping.getitem.main] return ""; }
Example #5
Source File: EnhancedScanRecords.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void scan( DynamoDbEnhancedClient enhancedClient) { try{ // Create a DynamoDbTable object DynamoDbTable<Customer> custTable = enhancedClient.table("Customer", TableSchema.fromBean(Customer.class)); // Get items in the Record table and write out the ID values Iterator<Customer> results = custTable.scan().items().iterator(); while (results.hasNext()) { Customer rec = results.next(); System.out.println("The record id is "+rec.getId()); } } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("Done"); }
Example #6
Source File: DeleteItem.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void deleteDymamoDBItem(DynamoDbClient ddb, String tableName, String key, String keyVal) { HashMap<String,AttributeValue> keyToGet = new HashMap<String,AttributeValue>(); keyToGet.put(key, AttributeValue.builder() .s(keyVal) .build()); DeleteItemRequest deleteReq = DeleteItemRequest.builder() .tableName(tableName) .key(keyToGet) .build(); try { ddb.deleteItem(deleteReq); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.delete_item.main] }
Example #7
Source File: SyncPagination.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void autoPaginationWithResume(DynamoDbClient client) { System.out.println("running AutoPagination with resume in case of errors...\n"); ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build(); ListTablesIterable responses = client.listTablesPaginator(listTablesRequest); ListTablesResponse lastSuccessfulPage = null; try { for (ListTablesResponse response : responses) { response.tableNames().forEach(System.out::println); lastSuccessfulPage = response; } } catch (DynamoDbException exception) { if (lastSuccessfulPage != null) { System.out.println(exception.getMessage()); } } }
Example #8
Source File: EnhancedTableSchema.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void putRecord(DynamoDbEnhancedClient enhancedClient){ try { // Create a DynamoDbTable object DynamoDbTable<Record> mappedTable = enhancedClient.table("Record", TABLE_SCHEMA); // Populate the table Record record = new Record() .setId("id-value") .setSort("sort-value") .setAttribute("one") .setAttribute2("two") .setAttribute3("three"); mappedTable.putItem(record); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("done"); }
Example #9
Source File: DynamoDBMappingPutItem.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void putRecord(DynamoDbEnhancedClient enhancedClient){ try { // Create a DynamoDbTable object DynamoDbTable<Record> mappedTable = enhancedClient.table("Record", TABLE_SCHEMA); // Populate the table Record record = new Record() .setId("id-value") .setSort("sort-value") .setAttribute("one") .setAttribute2("two") .setAttribute3("three"); mappedTable.putItem(record); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("done"); }
Example #10
Source File: CreateTable.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void createDynamoDBTable( DynamoDbEnhancedClient enhancedClient) { try { // Create a DynamoDbTable object DynamoDbTable<Record> mappedTable = enhancedClient.table("Record", TABLE_SCHEMA); // Create the table mappedTable.createTable(r -> r.provisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) .globalSecondaryIndices( EnhancedGlobalSecondaryIndex.builder() .indexName("gsi_1") .projection(p -> p.projectionType(ProjectionType.ALL)) .provisionedThroughput(DEFAULT_PROVISIONED_THROUGHPUT) .build())); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("done"); }
Example #11
Source File: ScanRecords.java From aws-doc-sdk-examples with Apache License 2.0 | 6 votes |
public static void scan( DynamoDbEnhancedClient enhancedClient) { try{ // Create a DynamoDbTable object DynamoDbTable<Record> mappedTable = enhancedClient.table("Record", TABLE_SCHEMA); // Get items in the Record table and write out the ID value Iterator<Record> results = mappedTable.scan().items().iterator(); while (results.hasNext()) { Record rec = results.next(); System.out.println("The record id is "+rec.getId()); } } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("Done"); }
Example #12
Source File: EnhancedClientIntegrationTest.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
@Test @Order(3) public void PutItem() { try { //Lets wait 20 secs for table to complete TimeUnit.SECONDS.sleep(20); EnhancedTableSchema.putRecord(enhancedClient); } catch (DynamoDbException | InterruptedException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("\n Test 3 passed"); }
Example #13
Source File: EnhancedClientIntegrationTest.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
@Test @Order(2) public void CreateTable() { try { CreateTable.createTable(ddb, enhancedTableName, enhancedTableKey ); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("\n Test 2 passed"); }
Example #14
Source File: EnhancedClientIntegrationTest.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
@Test @Order(8) public void DeleteTable() { try { DeleteTable.deleteDynamoDBTable(ddb,enhancedTableName); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("\n Test 8 passed"); }
Example #15
Source File: EnhancedClientIntegrationTest.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
@Test @Order(4) public void PutBatchItems() { try { EnhancedBatchWriteItems.putBatchRecords(enhancedClient); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("\n Test 4 passed"); }
Example #16
Source File: EnhancedClientIntegrationTest.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
@Test @Order(5) public void GetItem() { try { String result = EnhancedGetItem.getItem(enhancedClient); assertTrue(!result.isEmpty()); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("\n Test 5 passed"); }
Example #17
Source File: EnhancedClientIntegrationTest.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
@Test @Order(6) public void QueryRecords() { try { //Create a DynamoDbTable object String result = EnhancedQueryRecords.queryTable(enhancedClient); assertTrue(!result.isEmpty()); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("\n Test 6 passed"); }
Example #18
Source File: EnhancedPutItem.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void putRecord(DynamoDbEnhancedClient enhancedClient) { try { // Create a DynamoDbTable object DynamoDbTable<Customer> custTable = enhancedClient.table("Customer", TableSchema.fromBean(Customer.class)); // Create an Instant object LocalDate localDate = LocalDate.parse("2020-04-07"); LocalDateTime localDateTime = localDate.atStartOfDay(); Instant instant = localDateTime.toInstant(ZoneOffset.UTC); // Populate the table Customer custRecord = new Customer(); custRecord.setCustName("Susan Blue"); custRecord.setId("id103"); custRecord.setEmail("[email protected]"); custRecord.setRegistrationDate(instant) ; // Put the customer data into a DynamoDB table custTable.putItem(custRecord); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("done"); }
Example #19
Source File: PersistCase.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public void putRecord(String caseId, String employeeName, String email) { // Create a DynamoDbClient object Region region = Region.US_WEST_2; DynamoDbClient ddb = DynamoDbClient.builder() .region(region) .build(); // Create a DynamoDbEnhancedClient and use the DynamoDbClient object DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder() .dynamoDbClient(ddb) .build(); try { // Create a DynamoDbTable object DynamoDbTable<Case> caseTable = enhancedClient.table("Case", TableSchema.fromBean(Case.class)); // Create an Instat object LocalDate localDate = LocalDate.parse("2020-04-07"); LocalDateTime localDateTime = localDate.atStartOfDay(); Instant instant = localDateTime.toInstant(ZoneOffset.UTC); // Populate the table Case caseRecord = new Case(); caseRecord.setName(employeeName); caseRecord.setId(caseId); caseRecord.setEmail(email); caseRecord.setRegistrationDate(instant) ; // Put the case data into a DynamoDB table caseTable.putItem(caseRecord); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("done"); }
Example #20
Source File: EnhancedClientIntegrationTest.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
@Test @Order(7) public void ScanRecords() { try { EnhancedScanRecords.scan(enhancedClient); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("\n Test 7 passed"); }
Example #21
Source File: DynamoDBIO.java From beam with Apache License 2.0 | 5 votes |
@Override public boolean test(Throwable throwable) { return (throwable instanceof IOException || (throwable instanceof DynamoDbException) || (throwable instanceof DynamoDbException && ELIGIBLE_CODES.contains(((DynamoDbException) throwable).statusCode()))); }
Example #22
Source File: GetItem.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void getDynamoDBItem(DynamoDbClient ddb,String tableName,String key,String keyVal ) { HashMap<String,AttributeValue> keyToGet = new HashMap<String,AttributeValue>(); keyToGet.put(key, AttributeValue.builder() .s(keyVal).build()); // Create a GetItemRequest object GetItemRequest request = GetItemRequest.builder() .key(keyToGet) .tableName(tableName) .build(); try { Map<String,AttributeValue> returnedItem = ddb.getItem(request).item(); if (returnedItem != null) { Set<String> keys = returnedItem.keySet(); System.out.println("Table Attributes: \n"); for (String key1 : keys) { System.out.format("%s: %s\n", key1, returnedItem.get(key1).toString()); } } else { System.out.format("No item found with the key %s!\n", key); } } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.get_item.main] }
Example #23
Source File: CreateTable.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static String createTable(DynamoDbClient ddb, String tableName, String key) { // Create the CreateTableRequest object CreateTableRequest request = CreateTableRequest.builder() .attributeDefinitions(AttributeDefinition.builder() .attributeName(key) .attributeType(ScalarAttributeType.S) .build()) .keySchema(KeySchemaElement.builder() .attributeName(key) .keyType(KeyType.HASH) .build()) .provisionedThroughput(ProvisionedThroughput.builder() .readCapacityUnits(new Long(10)) .writeCapacityUnits(new Long(10)) .build()) .tableName(tableName) .build(); String newTable =""; try { CreateTableResponse response = ddb.createTable(request); newTable = response.tableDescription().tableName(); return newTable; } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.create_table.main] return ""; }
Example #24
Source File: Query.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static int queryTable(DynamoDbClient ddb, String tableName, String partitionKeyName, String partitionKeyVal, String partitionAlias) { // Set up an alias for the partition key name in case it's a reserved word HashMap<String,String> attrNameAlias = new HashMap<String,String>(); attrNameAlias.put(partitionAlias, partitionKeyName); // Set up mapping of the partition name with the value HashMap<String, AttributeValue> attrValues = new HashMap<String,AttributeValue>(); attrValues.put(":"+partitionKeyName, AttributeValue.builder().s(partitionKeyVal).build()); // Cretae a QueryRequest object QueryRequest queryReq = QueryRequest.builder() .tableName(tableName) .keyConditionExpression(partitionAlias + " = :" + partitionKeyName) .expressionAttributeNames(attrNameAlias) .expressionAttributeValues(attrValues) .build(); try { QueryResponse response = ddb.query(queryReq); return response.count(); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } return -1; }
Example #25
Source File: UpdateTable.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void updateDynamoDBTable(DynamoDbClient ddb, String tableName, Long readCapacity, Long writeCapacity) { System.out.format( "Updating %s with new provisioned throughput values\n", tableName); System.out.format("Read capacity : %d\n", readCapacity); System.out.format("Write capacity : %d\n", writeCapacity); ProvisionedThroughput tableThroughput = ProvisionedThroughput.builder() .readCapacityUnits(readCapacity) .writeCapacityUnits(writeCapacity) .build(); UpdateTableRequest request = UpdateTableRequest.builder() .provisionedThroughput(tableThroughput) .tableName(tableName) .build(); try { ddb.updateTable(request); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } // snippet-end:[dynamodb.java2.update_table.main] System.out.println("Done!"); }
Example #26
Source File: EnhancedQueryRecords.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static String queryTable(DynamoDbEnhancedClient enhancedClient) { try{ // Create a DynamoDbTable object DynamoDbTable<Customer> mappedTable = enhancedClient.table("Customer", TableSchema.fromBean(Customer.class)); // Create a QueryConditional object that's used in the query operation QueryConditional queryConditional = QueryConditional .keyEqualTo(Key.builder() .partitionValue("id120") .build()); // Get items in the Record table and write out the ID value Iterator<Customer> results = mappedTable.query(queryConditional).items().iterator(); String result=""; while (results.hasNext()) { Customer rec = results.next(); result = rec.getId(); System.out.println("The record id is "+result); } return result; } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } return ""; // snippet-end:[dynamodb.java2.mapping.query.main] }
Example #27
Source File: EnhancedQueryRecordsWithFilter.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void queryTableFilter(DynamoDbEnhancedClient enhancedClient) { try{ // Create a DynamoDbTable object DynamoDbTable<EnhancedQueryRecords.Customer> mappedTable = enhancedClient.table("Customer", TableSchema.fromBean(EnhancedQueryRecords.Customer.class)); // Get the row where email is [email protected] AttributeValue att = AttributeValue.builder() .s("[email protected]") .build(); Map<String, AttributeValue> expressionValues = new HashMap<>(); expressionValues.put(":value", att); Expression expression = Expression.builder() .expression("email = :value") .expressionValues(expressionValues) .build(); // Create a QueryConditional object that's used in the query operation QueryConditional queryConditional = QueryConditional .keyEqualTo(Key.builder().partitionValue("id103") .build()); // Get items in the Customer table and write out the ID value Iterator<EnhancedQueryRecords.Customer> results = mappedTable.query(r -> r.queryConditional(queryConditional).filterExpression(expression)).items().iterator(); while (results.hasNext()) { EnhancedQueryRecords.Customer rec = results.next(); System.out.println("The record id is "+rec.getId()); } } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("Done"); // snippet-end:[dynamodb.java2.mapping.queryfilter.main] }
Example #28
Source File: QueryRecords.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static String queryTable(DynamoDbEnhancedClient enhancedClient) { try{ // Create a DynamoDbTable object DynamoDbTable<Record> mappedTable = enhancedClient.table("Record", TABLE_SCHEMA); // Create a QueryConditional object that is used in the query operation QueryConditional queryConditional = QueryConditional .keyEqualTo(Key.builder() .partitionValue("id-value") .build()); // Get items in the Record table and write out the ID value Iterator<Record> results = mappedTable.query(queryConditional).items().iterator(); String result=""; while (results.hasNext()) { Record rec = results.next(); result = rec.getId(); System.out.println("The record id is "+result); } return result; } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } return ""; // snippet-end:[dynamodb.java2.enhanced_query.main] }
Example #29
Source File: DynamoDbBeanExample.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void putRecord(DynamoDbEnhancedClient enhancedClient) { try { //Create a DynamoDbTable object DynamoDbTable<Customer> custTable = enhancedClient.table("Customer", TableSchema.fromBean(Customer.class)); //Create am Instat LocalDate localDate = LocalDate.parse("2020-04-07"); LocalDateTime localDateTime = localDate.atStartOfDay(); Instant instant = localDateTime.toInstant(ZoneOffset.UTC); //Populate the Table Customer custRecord = new Customer(); custRecord.setCustName("Susan Blue"); custRecord.setId("id103"); custRecord.setEmail("[email protected]"); custRecord.setRegistrationDate(instant) ; //Put the customer data into a DynamoDB table custTable.putItem(custRecord); } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("done"); }
Example #30
Source File: QueryRecordsWithFilter.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void queryTableFilter(DynamoDbEnhancedClient enhancedClient) { try{ // Create a DynamoDbTable object DynamoDbTable<Record> mappedTable = enhancedClient.table("Record", TABLE_SCHEMA); // Get the row where Attribute3 is 20 AttributeValue att = AttributeValue.builder() .s("20") .build(); Map<String, AttributeValue> expressionValues = new HashMap<>(); expressionValues.put(":value", att); Expression expression = Expression.builder() .expression("attribute3 = :value") .expressionValues(expressionValues) .build(); // Create a QueryConditional object that is used in the query operation QueryConditional queryConditional = QueryConditional .keyEqualTo(Key.builder().partitionValue("id-value") .build()); // Get items in the Record table and write out the ID value Iterator<Record> results = mappedTable.query(queryConditional).items().iterator(); while (results.hasNext()) { Record rec = results.next(); System.out.println("The record id is "+rec.getId()); } } catch (DynamoDbException e) { System.err.println(e.getMessage()); System.exit(1); } System.out.println("Done"); // snippet-end:[dynamodb.java2.enhanced_queryfilter.main] }