Skip to content

Instantly share code, notes, and snippets.

@Aleksandr-Filichkin
Last active Aug 14, 2021
Embed
What would you like to do?
public class BookHandler implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
private static final String TABLE_NAME = "books";
private static final EnhancedRequestDispatcher ENHANCED_REQUEST_DISPATCHER = initDispatcher();
static {
ENHANCED_REQUEST_DISPATCHER.warmUp();
}
private static EnhancedRequestDispatcher initDispatcher() {
DynamoDbEnhancedClient dynamoDbEnhancedClient = DynamoDbEnhancedClient.builder()
.dynamoDbClient(DynamoDbClient.builder()
.credentialsProvider(EnvironmentVariableCredentialsProvider.create())
.region(Region.US_EAST_1)
.build())
.build();
DynamoDbTable<Book> dynamoDbTable = dynamoDbEnhancedClient.table(TABLE_NAME, TableSchema.fromBean(Book.class));
return new EnhancedRequestDispatcher(new EnhancedClientBookStorage(dynamoDbTable), new ObjectMapper());
}
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent apiGatewayProxyRequestEvent, Context context) {
return ENHANCED_REQUEST_DISPATCHER.dispatch(apiGatewayProxyRequestEvent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment