Scanning Data From DynamoDB


You can query or scan data from dynamodb. Try different ways to scan from DynamoDB.

Solution Summary: 

You can do DynamoDB scan in two ways:

  1. Calling scan on a Table object.
  2. Calling scan on the client object of type AmazonDynamoDB.

Calling scan on a Table object can be done as follows:


    AmazonDynamoDB client;


        DynamoDB dynamoDB = new DynamoDB(client);

        Table table = dynamoDB.getTable(demoTableName);


        ScanSpec scanSpec = new ScanSpec();

        List<Map<String, String>> finalList = new ArrayList<>();

        Map<String, String> rowMap = new HashMap<>();


        ItemCollection<ScanOutcome> scanItems = table.scan(scanSpec);


        Iterator<Item> scanItemsIterator = scanItems.iterator();


        while (scanItemsIterator.hasNext()) {

            Item item =;

            String name = item.getString("Name");

            String desig = item.getString("Designation");

            System.out.println("adding "+name + " as "+ desig);

            rowMap.put(name, desig);




        System.out.println("SCAN LIST RESULT:");



Calling scan on the client object of type AmazonDynamoDB can be done as:


    AmazonDynamoDB client;

        System.out.println("Scanning with ScanRequest");

        ScanRequest scanRequest = new ScanRequest()

                .withProjectionExpression("#Name, Designation")






        ScanResult result = client.scan(scanRequest);

        final List<Map<String, AttributeValue>> resultItems = result.getItems();


        final List<Map<String, String>> rowMaps = new ArrayList<>();

        resultItems.forEach(map -> {

            final Map<String, String> m = map.entrySet()


                    .collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().getS()));




        System.out.println("SCAN LIST RESULT:");



Both approaches have their own merits; for instance, first approach gives more flexibility, but will require an extra call to dynamodb to first get the table object and then do the query.

Go through the documentation and decide on the best approach suitable for your case.


We learn together, do innovations and then document them at

Offline Contact
We connect physically only in Bengaluru currently, but most of our activities happen online. Please follow us here or in social media for more details.
WhatsApp (Primary): (+91) 7411174113
Phone (Escalations): (+91) 7411174114

Business newsletter

Complete the form below, and we'll send you an e-mail every now and again with all the latest news.

About us

Team Cloudericks is a community started by Heartin Kanikathottu to learn about and master cloud computing. Our current focus is on Amazon Web Servivces. aims to document what we learn. We believe that knowledge is useless unless you share it; the more you share, the more you learn.

Recent comments

Photo Stream