// snippet-sourcedescription:[DynamoDBScanItems demonstrates how to return one or more items and item attributes by accessing every item in a table.]
// snippet-service:[dynamodb]
// snippet-keyword:[Code Sample]]
// snippet-sourcesyntax:[java]
// snippet-keyword:[Amazon DynamoDB]
// snippet-sourcetype:[full-example]
// snippet-sourcedate:[2020-01-27]
// snippet-sourceauthor:[AWS-scmacdon]

/**
 * Copyright 2018-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * This file is licensed under the Apache License, Version 2.0 (the "License").
 * You may not use this file except in compliance with the License. A copy of
 * the License is located at
 *
 * http://aws.amazon.com/apache2.0/
 *
 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */

// snippet-start:[dynamodb.java2.dynamoDB_scan.complete]

package com.example.dynamodb;

// snippet-start:[dynamodb.java2.dynamoDB_scan.import]
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.AttributeValue;
import software.amazon.awssdk.services.dynamodb.model.DynamoDbException;
import software.amazon.awssdk.services.dynamodb.model.ScanRequest;
import software.amazon.awssdk.services.dynamodb.model.ScanResponse;
import java.util.Map;
import java.util.Set;
// snippet-end:[dynamodb.java2.dynamoDB_scan.import]

/**
 * Scans information from an AWS DynamoDB table.
 *
 * Takes the name of the table as input.
 *
 * This code expects that you have AWS credentials set up, as described here:
 * http://docs.aws.amazon.com/java-sdk/latest/developer-guide/setup-credentials.html
 */

public class DynamoDBScanItems {

    public static void main(String[] args) {

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

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

        // snippet-start:[dynamodb.java2.dynamoDB_scan.main]
        String tableName = args[0];

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

        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]
    }
}
// snippet-end:[dynamodb.java2.dynamoDB_scan.complete]

@@ -163,24 +163,31 @@
 ervice:%5B
-d
+Amazon D
 ynamo
-db
+DB
 %5D%0A// sni
@@ -212,17 +212,16 @@
  Sample%5D
-%5D
 %0A// snip
@@ -414,18 +414,8 @@
 ght 
-2018-2020 
 Amaz
@@ -935,66 +935,8 @@
 */%0A%0A
-// snippet-start:%5Bdynamodb.java2.dynamoDB_scan.complete%5D%0A%0A
 pack
@@ -1858,16 +1858,17 @@
 %0A       
+ 
 final St
@@ -1903,20 +1903,16 @@
         
-    
 %22Usage:%5C
@@ -1928,28 +1928,24 @@
             
-  
-  
 %22    DynamoD
@@ -1962,36 +1962,32 @@
  %3Ctable%3E%5Cn%5Cn%22 +%0A
-    
                 
@@ -2011,28 +2011,24 @@
             
-    
 %22    table -
@@ -2100,20 +2100,16 @@
         
-    
 %22Example
@@ -2107,36 +2107,32 @@
  %22Example:%5Cn%22 +%0A
-    
                 
@@ -2170,20 +2170,16 @@
         
- 
-   
 if (args
@@ -2189,28 +2189,24 @@
 ngth %3C 1) %7B%0A
-    
             
@@ -2240,28 +2240,24 @@
             
-    
 System.exit(
@@ -2272,75 +2272,9 @@
     
-  
-  %7D%0A%0A        // snippet-start:%5Bdynamodb.java2.dynamoDB_scan.main%5D
+%7D
 %0A   
@@ -2389,14 +2389,14 @@
 .US_
-W
 E
+A
 ST_
-2
+1
 ;%0A  
@@ -2462,32 +2462,204 @@
 region).build();
+%0A        scanItems(ddb,tableName);%0A    %7D%0A%0A    // snippet-start:%5Bdynamodb.java2.dynamoDB_scan.main%5D%0A    public static void scanItems( DynamoDbClient ddb,String tableName ) %7B
 %0A%0A        try %7B%0A
@@ -2658,17 +2658,16 @@
   try %7B%0A
-%0A
         
@@ -3270,33 +3270,32 @@
 ce();%0A        %7D%0A
-%0A
         // snipp
@@ -3349,59 +3349,4 @@
 %7D%0A%7D%0A
-// snippet-end:%5Bdynamodb.java2.dynamoDB_scan.complete%5D%0A

Update DynamoDBScanItems.java