Skip to content

Instantly share code, notes, and snippets.

@Aleksandr-Filichkin
Last active August 14, 2021 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Aleksandr-Filichkin/9ba8c1859e01d67bc09348e48e67a6a4 to your computer and use it in GitHub Desktop.
Save Aleksandr-Filichkin/9ba8c1859e01d67bc09348e48e67a6a4 to your computer and use it in GitHub Desktop.
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