-
-
Save Aleksandr-Filichkin/9ba8c1859e01d67bc09348e48e67a6a4 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
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