2 * Copyright (c) 2010-2020 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.persistence.dynamodb.internal;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 import com.amazonaws.auth.AWSCredentials;
19 import com.amazonaws.auth.AWSStaticCredentialsProvider;
20 import com.amazonaws.regions.Regions;
21 import com.amazonaws.services.dynamodbv2.AmazonDynamoDB;
22 import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClientBuilder;
23 import com.amazonaws.services.dynamodbv2.document.DynamoDB;
26 * Shallow wrapper for Dynamo DB wrappers
28 * @author Sami Salonen - Initial contribution
30 public class DynamoDBClient {
31 private final Logger logger = LoggerFactory.getLogger(DynamoDBClient.class);
32 private DynamoDB dynamo;
33 private AmazonDynamoDB client;
35 public DynamoDBClient(AWSCredentials credentials, Regions region) {
36 client = AmazonDynamoDBClientBuilder.standard().withRegion(region)
37 .withCredentials(new AWSStaticCredentialsProvider(credentials)).build();
38 dynamo = new DynamoDB(client);
41 public DynamoDBClient(DynamoDBConfig clientConfig) {
42 this(clientConfig.getCredentials(), clientConfig.getRegion());
45 public AmazonDynamoDB getDynamoClient() {
49 public DynamoDB getDynamoDB() {
53 public void shutdown() {
57 public boolean checkConnection() {
59 dynamo.listTables(1).firstPage();
60 } catch (Exception e) {
61 logger.warn("Got internal server error when trying to list tables: {}", e.getMessage());