Skip to content

Instantly share code, notes, and snippets.

@theawesomenayak
Last active October 24, 2020 11:16
Show Gist options
  • Save theawesomenayak/d9ce18ec8aa219c529e5072705a3f10d to your computer and use it in GitHub Desktop.
Save theawesomenayak/d9ce18ec8aa219c529e5072705a3f10d to your computer and use it in GitHub Desktop.
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