Last active
October 24, 2020 11:17
-
-
Save theawesomenayak/0582463529a6527ee35b5062e5c50b67 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.AttributeValue; | |
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest; | |
.... | |
public String write(final Pet pet) { | |
final String id = UUID.randomUUID().toString(); | |
final PutItemRequest putItemRequest = PutItemRequest.builder() | |
.tableName("pet-store") | |
.item( | |
Map.of( | |
"id", AttributeValue.builder().s(id).build(), | |
"name", AttributeValue.builder().s(pet.getName()).build(), | |
"age", AttributeValue.builder().n(Integer.toString(pet.getAge())).build(), | |
"category", AttributeValue.builder().s(pet.getCategory()).build() | |
) | |
) | |
.build(); | |
dynamoDbClient.putItem(putItemRequest); | |
return id; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment