software.amazon.awssdk.services.dynamodb.DynamoDbClient Java Examples

The following examples show how to use software.amazon.awssdk.services.dynamodb.DynamoDbClient. 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: SyncPagination.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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 #2
Source File: EnhancedQueryRecords.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Create a DynamoDbClient object
        Region region = Region.US_EAST_1;
        DynamoDbClient ddb = DynamoDbClient.builder()
                .region(region)
                .build();

        // Create a DynamoDbEnhancedClient and use the DynamoDbClient object
        DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder()
                .dynamoDbClient(ddb)
                .build();

        String result = queryTable(enhancedClient);
        System.out.println(result);
    }
 
Example #3
Source File: SyncPagination.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void manualPagination(DynamoDbClient client) {
    System.out.println("running ManualPagination...\n");

    ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build();
    boolean done = false;
    while (!done) {
        ListTablesResponse listTablesResponse = client.listTables(listTablesRequest);
        System.out.println(listTablesResponse.tableNames());

        if (listTablesResponse.lastEvaluatedTableName() == null) {
            done = true;
        }

        listTablesRequest = listTablesRequest.toBuilder()
                .exclusiveStartTableName(listTablesResponse.lastEvaluatedTableName())
                .build();
    }
}
 
Example #4
Source File: DynamoDBUtils.java    From ShedLock with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a locking table with the given name.
 * <p>
 * This method does not check if a table with the given name exists already.
 *
 * @param ddbClient  v2 of DynamoDBClient
 * @param tableName  table to be used
 * @param throughput AWS {@link ProvisionedThroughput throughput requirements} for the given lock setup
 * @return           the table name
 *
 * @throws ResourceInUseException
 *         The operation conflicts with the resource's availability. You attempted to recreate an
 *         existing table.
 */
public static String createLockTable(
        DynamoDbClient ddbClient,
        String tableName,
        ProvisionedThroughput throughput
) {

    CreateTableRequest request = CreateTableRequest.builder()
            .tableName(tableName)
            .keySchema(KeySchemaElement.builder()
                    .attributeName(ID)
                    .keyType(KeyType.HASH)
                    .build())
            .attributeDefinitions(AttributeDefinition.builder()
                    .attributeName(ID)
                    .attributeType(ScalarAttributeType.S)
                    .build())
            .provisionedThroughput(throughput)
            .build();
    ddbClient.createTable(request);
    return tableName;
}
 
Example #5
Source File: UpdateTable.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
    final String USAGE = "\n" +
            "Usage:\n" +
            "    UpdateTable <table> <read> <write>\n\n" +
            "Where:\n" +
            "    table - the table to put the item in (i.e., Music3)\n" +
            "    read  - the new read capacity of the table (i.e., 16)\n" +
            "    write - the new write capacity of the table (i.e., 10)\n\n" +
            "Example:\n" +
            "    UpdateTable Music3 16 10\n";

    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String tableName = args[0];
    Long readCapacity = Long.parseLong(args[1]);
    Long writeCapacity = Long.parseLong(args[2]);

    // Create the DynamoDbClient object
    Region region = Region.US_WEST_2;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();

    updateDynamoDBTable(ddb, tableName, readCapacity, writeCapacity);
}
 
Example #6
Source File: QueryRecords.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

        // Create a DynamoDbClient object
        Region region = Region.US_EAST_1;
        DynamoDbClient ddb = DynamoDbClient.builder()
                .region(region)
                .build();

        // Create a DynamoDbEnhancedClient and use the DynamoDbClient object
        DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder()
                .dynamoDbClient(ddb)
                .build();

        String result = queryTable(enhancedClient);
        System.out.println(result);
    }
 
Example #7
Source File: Aws2ITest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
  System.getProperties().setProperty("sqlite4java.library.path", "src/test/resources/libs");

  final DynamoDBProxyServer server = ServerRunner.createServerFromCommandLineArgs(new String[] {"-inMemory", "-port", "8000"});
  server.start();

  final DynamoDbClient dbClient = buildClient();
  try {
    createTable(dbClient, "tableName-" + ThreadLocalRandom.current().nextLong(Long.MAX_VALUE));
  }
  catch (final Exception e) {
    System.out.println("Exception: " + e.getMessage() + "\nIgnoring.");
  }

  server.stop();
  TestUtil.checkSpan(new ComponentSpanCount("java-aws-sdk", 1));
  System.exit(0);
}
 
Example #8
Source File: DeleteItem.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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 #9
Source File: EnhancedClientGetOverheadBenchmark.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Setup
public void setup(Blackhole bh) {
    dynamoDb = DynamoDbClient.builder()
            .credentialsProvider(StaticCredentialsProvider.create(
                    AwsBasicCredentials.create("akid", "skid")))
            .httpClient(new MockHttpClient(testItem.responseContent, "{}"))
            .overrideConfiguration(o -> o.addExecutionInterceptor(new ExecutionInterceptor() {
                @Override
                public void afterUnmarshalling(Context.AfterUnmarshalling context,
                                               ExecutionAttributes executionAttributes) {
                    bh.consume(context);
                    bh.consume(executionAttributes);
                }
            }))
            .build();

    DynamoDbEnhancedClient ddbEnh = DynamoDbEnhancedClient.builder()
            .dynamoDbClient(dynamoDb)
            .build();

    table = ddbEnh.table(testItem.name(), testItem.tableSchema);
}
 
Example #10
Source File: DynamoDBMappingGetItem.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

         // Create a DynamoDbClient object
        Region region = Region.US_EAST_1;
        DynamoDbClient ddb = DynamoDbClient.builder()
                .region(region)
                .build();

           // Create a DynamoDbEnhancedClient and use the DynamoDbClient object
           DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder()
                   .dynamoDbClient(ddb)
                   .build();

           String result = getItem(enhancedClient);
           System.out.println(result);
       }
 
Example #11
Source File: DescribeTable.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

        final String USAGE = "\n" +
                "Usage:\n" +
                "    DescribeTable <table>\n\n" +
                "Where:\n" +
                "    table - the table to get information about (i.e., Music3)\n\n" +
                "Example:\n" +
                "    DescribeTable Music3\n";

        if (args.length < 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        /* Read the name from command args */
        String tableName = args[0];
        System.out.format("Getting description for %s\n\n", tableName);

        // Create the DynamoDbClient object
        Region region = Region.US_EAST_1;
        DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();

        describeDymamoDBTable(ddb,tableName);

    }
 
Example #12
Source File: DeleteTable.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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 #13
Source File: GetItem.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: PersistCase.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
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 #15
Source File: Aws2ITest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static void createTable(final DynamoDbClient dbClient, final String tableName) {
  final String partitionKeyName = tableName + "-pk";
  final CreateTableRequest createTableRequest = CreateTableRequest
    .builder().tableName(tableName)
    .keySchema(KeySchemaElement.builder().attributeName(partitionKeyName).keyType(KeyType.HASH).build())
    .attributeDefinitions(AttributeDefinition.builder().attributeName(partitionKeyName).attributeType("S").build())
    .provisionedThroughput(ProvisionedThroughput.builder().readCapacityUnits(10L).writeCapacityUnits(5L).build())
    .build();
  dbClient.createTable(createTableRequest);
  System.out.println("Table " + tableName + " created");
}
 
Example #16
Source File: SyncPagination.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        final String USAGE = "\n" +
                "Usage:\n" +
                "    AsynPagination <type>\n\n" +
                "Where:\n" +
                "    type - the type of pagination (auto, manual or default) \n\n" +
                "Example:\n" +
                "    AsynPagination auto\n";

        if (args.length < 1) {
            System.out.println(USAGE);
            System.exit(1);
        }

        String method = args[0];

        Region region = Region.US_EAST_1;
        DynamoDbClient ddb = DynamoDbClient.builder()
                .region(region)
                .build();


        switch (method.toLowerCase()) {
            case "manual":
                manualPagination(ddb);
                break;
            case "auto":
                autoPagination(ddb);
                autoPaginationWithResume(ddb);
                break;
            default:
                manualPagination(ddb);
                autoPagination(ddb);
                autoPaginationWithResume(ddb);
        }
    }
 
Example #17
Source File: V2DefaultClientCreationBenchmark.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
@Override
@Benchmark
public void createClient(Blackhole blackhole) throws Exception {
    client = DynamoDbClient.builder()
                           .endpointDiscoveryEnabled(false)
                           .httpClient(ApacheHttpClient.builder().build()).build();
    blackhole.consume(client);
}
 
Example #18
Source File: GetItem.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final String USAGE = "\n" +
            "Usage:\n" +
            "    GetItem <table> <key> <keyVal>\n\n" +
            "Where:\n" +
            "    table - the table from which an item is retrieved (i.e., Music3)\n" +
            "    key -  the key used in the table (i.e., Artist) \n" +
            "    keyval  - the key value that represents the item to get (i.e., Famous Band)\n" +
            " Example:\n" +
            "    Music3 Artist Famous Band\n" +
            "  **Warning** This program will actually retrieve an item\n" +
            "            that you specify!\n";

    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String tableName = args[0];
    String key = args[1];
    String keyVal = args[2];

    System.out.format("Retrieving item \"%s\" from \"%s\"\n",
            keyVal, tableName);

    // Create the DynamoDbClient object
    Region region = Region.US_WEST_2;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();

    getDynamoDBItem(ddb, tableName, key, keyVal);
}
 
Example #19
Source File: TableUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Wait for the table to reach the desired status and returns the table
 * description
 *
 * @param dynamo
 *            Dynamo client to use
 * @param tableName
 *            Table name to poll status of
 * @param desiredStatus
 *            Desired {@link TableStatus} to wait for. If null this method
 *            simply waits until DescribeTable returns something non-null
 *            (i.e. any status)
 * @param timeout
 *            Timeout in milliseconds to continue to poll for desired status
 * @param interval
 *            Time to wait in milliseconds between poll attempts
 * @return Null if DescribeTables never returns a result, otherwise the
 *         result of the last poll attempt (which may or may not have the
 *         desired state)
 * @throws {@link
 *             IllegalArgumentException} If timeout or interval is invalid
 */
private static TableDescription waitForTableDescription(final DynamoDbClient dynamo, final String tableName,
                                                        TableStatus desiredStatus, final int timeout, final int interval)
        throws InterruptedException, IllegalArgumentException {
    if (timeout < 0) {
        throw new IllegalArgumentException("Timeout must be >= 0");
    }
    if (interval <= 0 || interval >= timeout) {
        throw new IllegalArgumentException("Interval must be > 0 and < timeout");
    }
    long startTime = System.currentTimeMillis();
    long endTime = startTime + timeout;

    TableDescription table = null;
    while (System.currentTimeMillis() < endTime) {
        try {
            table = dynamo.describeTable(DescribeTableRequest.builder().tableName(tableName).build()).table();
            if (desiredStatus == null || table.tableStatus().equals(desiredStatus)) {
                return table;

            }
        } catch (ResourceNotFoundException rnfe) {
            // ResourceNotFound means the table doesn't exist yet,
            // so ignore this error and just keep polling.
        }

        Thread.sleep(interval);
    }
    return table;
}
 
Example #20
Source File: TableUtils.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the table and ignores any errors if it already exists.
 * @param dynamo The Dynamo client to use.
 * @param createTableRequest The create table request.
 * @return True if created, false otherwise.
 */
public static boolean createTableIfNotExists(final DynamoDbClient dynamo, final CreateTableRequest createTableRequest) {
    try {
        dynamo.createTable(createTableRequest);
        return true;
    } catch (final ResourceInUseException e) {
        if (log.isTraceEnabled()) {
            log.trace("Table " + createTableRequest.tableName() + " already exists", e);
        }
    }
    return false;
}
 
Example #21
Source File: DynamoJobMetaRepositoryTest.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
private static DynamoDbClient getDynamoDbClient() {
    String endpointUri = "http://" + dynamodb.getContainerIpAddress() + ":" +
            dynamodb.getMappedPort(8000);

    return DynamoDbClient.builder()
            .endpointOverride(URI.create(endpointUri))
            .region(Region.EU_CENTRAL_1)
            .credentialsProvider(StaticCredentialsProvider
                    .create(AwsBasicCredentials.create("acc", "sec"))).build();
}
 
Example #22
Source File: DynamoDBTestBase.java    From aws-sdk-java-v2 with Apache License 2.0 5 votes vote down vote up
public static void waitForTableToBecomeDeleted(DynamoDbClient dynamo, String tableName) {
    log.info(() -> "Waiting for " + tableName + " to become Deleted...");

    long startTime = System.currentTimeMillis();
    long endTime = startTime + (60_000);
    while (System.currentTimeMillis() < endTime) {
        try {
            Thread.sleep(5_000);
        } catch (Exception e) {
            // Ignored or expected.
        }
        try {
            DescribeTableRequest request = DescribeTableRequest.builder().tableName(tableName).build();
            TableDescription table = dynamo.describeTable(request).table();

            log.info(() -> "  - current state: " + table.tableStatusAsString());
            if (table.tableStatus() == TableStatus.DELETING) {
                continue;
            }
        } catch (AwsServiceException exception) {
            if (exception.awsErrorDetails().errorCode().equalsIgnoreCase("ResourceNotFoundException")) {
                log.info(() -> "successfully deleted");
                return;
            }
        }
    }

    throw new RuntimeException("Table " + tableName + " never went deleted");
}
 
Example #23
Source File: DynamoDBEnhanced.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public void injectDynamoItem(Greeting item){

        Region region = Region.US_EAST_1;
        DynamoDbClient ddb = DynamoDbClient.builder()
                .region(region)
                .credentialsProvider(EnvironmentVariableCredentialsProvider.create())
                .build();

        try {

            DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder()
                    .dynamoDbClient(ddb)
                    .build();

            //Create a DynamoDbTable object
            DynamoDbTable<GreetingItems> mappedTable = enhancedClient.table("Greeting", TABLE_SCHEMA);
            GreetingItems gi = new GreetingItems();
            gi.setName(item.getName());
            gi.setMessage(item.getBody());
            gi.setTitle(item.getTitle());
            gi.setId(item.getId());

            PutItemEnhancedRequest enReq = PutItemEnhancedRequest.builder(GreetingItems.class)
                    .item(gi)
                    .build();

            mappedTable.putItem(enReq);

        } catch (Exception e) {
            e.getStackTrace();
        }

    }
 
Example #24
Source File: DynamoJobRepository.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
public DynamoJobRepository(DynamoDbClient dynamoDbClient, final String tableName, int pageSize) {
    super(dynamoDbClient, tableName);
    this.pageSize = pageSize;
    dynamoDbClient.describeTable(DescribeTableRequest.builder()
            .tableName(tableName)
            .build());
}
 
Example #25
Source File: ScanRecords.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        // Create a DynamoDbClient object
        Region region = Region.US_EAST_1;
        DynamoDbClient ddb = DynamoDbClient.builder()
                .region(region)
                .build();
        // Create a DynamoDbEnhancedClient and use the DynamoDbClient object
        DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder()
                .dynamoDbClient(ddb)
                .build();

        scan(enhancedClient);
    }
 
Example #26
Source File: DynamoJobsConfiguration.java    From edison-microservice with Apache License 2.0 5 votes vote down vote up
@Bean
public JobMetaRepository jobMetaRepository(final DynamoDbClient dynamoDbClient,
                                           final @Value("${edison.jobs.dynamo.jobmeta.tableName}") String tableName) {
    LOG.info("===============================");
    LOG.info("Using DynamoJobMetaRepository with tableName {}.", tableName);
    LOG.info("===============================");
    return new DynamoJobMetaRepository(dynamoDbClient, tableName);
}
 
Example #27
Source File: DynamoDBLockProviderIntegrationTest.java    From ShedLock with Apache License 2.0 5 votes vote down vote up
/**
 * Create a standard AWS v2 SDK client pointing to the local DynamoDb instance
 *
 * @return A DynamoDbClient pointing to the local DynamoDb instance
 */
static DynamoDbClient createClient() {
    String endpoint = "http://" + dynamoDbContainer.getContainerIpAddress() + ":" + dynamoDbContainer.getFirstMappedPort();
    return DynamoDbClient.builder()
        .endpointOverride(URI.create(endpoint))
        // The region is meaningless for local DynamoDb but required for client builder validation
        .region(Region.US_EAST_1)
        .credentialsProvider(StaticCredentialsProvider.create(
            AwsBasicCredentials.create("dummy-key", "dummy-secret"))
        )
        .build();
}
 
Example #28
Source File: EnhancedScanRecords.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {

        // Create a DynamoDbClient object
        Region region = Region.US_EAST_1;
        DynamoDbClient ddb = DynamoDbClient.builder()
                .region(region)
                .build();
        // Create a DynamoDbEnhancedClient and use the DynamoDbClient object
        DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder()
                .dynamoDbClient(ddb)
                .build();

        scan(enhancedClient);
    }
 
Example #29
Source File: CreateTableCompositeKey.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final String USAGE = "\n" +
            "Usage:\n" +
            "    CreateTable <table>\n\n" +
            "Where:\n" +
            "    table - the table to create (i.e., Music3)\n\n" +
            "Example:\n" +
            "    CreateTable Music3\n";

   if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }


    /* Read the table name from command args */
    String tableName = args[0];

    // Create the DynamoDbClient object
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder().region(region).build();

    System.out.format("Creating table %s\n with a composite primary key:\n", tableName);
    System.out.format("* Language - partition key\n");
    System.out.format("* Greeting - sort key\n");

    String tableId =createTableComKey(ddb,tableName);
    System.out.println("The table ID is "+tableId);

}
 
Example #30
Source File: DeleteTable.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final String USAGE = "\n" +
            "Usage:\n" +
            "    DeleteTable <table>\n\n" +
            "Where:\n" +
            "    table - the table to delete (i.e., Music3)\n\n" +
            "Example:\n" +
            "    DeleteTable Music3\n\n" +
            "**Warning** This program will actually delete the table\n" +
            "            that you specify!\n";

    if (args.length < 1) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String tableName = args[0];
    System.out.format("Deleting table %s...\n", tableName);


    // Create the DynamoDbClient object
    Region region = Region.US_EAST_1;
    DynamoDbClient ddb = DynamoDbClient.builder()
            .region(region)
            .build();

    deleteDynamoDBTable(ddb, tableName);
}