Last active
October 24, 2020 11:16
-
-
Save theawesomenayak/d9ce18ec8aa219c529e5072705a3f10d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import software.amazon.awssdk.services.dynamodb.model.ScanRequest; | |
import software.amazon.awssdk.services.dynamodb.model.ScanResponse; | |
.... | |
public List<Pet> read() { | |
final ScanRequest scanRequest = ScanRequest.builder() | |
.tableName("pet-store") | |
.build(); | |
final ScanResponse scanResponse = dynamoDbClient.scan(scanRequest); | |
final List<Map<String, AttributeValue>> returnedItems = scanResponse.items(); | |
final List<Pet> pets = new ArrayList<>(); | |
returnedItems.forEach(item -> { | |
final Pet pet = new Pet(); | |
pet.setId(item.get("id").s()); | |
pet.setName(item.get("name").s()); | |
pet.setAge(Integer.parseInt(item.get("age").n())); | |
pet.setCategory(item.get("category").s()); | |
pets.add(pet); | |
}); | |
return pets; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment