ablog

不器用で落着きのない技術者のメモ

YCSB から Amazon KeySpaces に SigV4 認証でアクセスする

  • YCSB/cassandra/pom.xml を以下の通り編集
    <cassandra.cql.version>3.7.2</cassandra.cql.version>
  • YCSB/cassandra/pom.xml に以下を追記
    <dependency>
        <groupId>software.aws.mcs</groupId>
        <artifactId>aws-sigv4-auth-cassandra-java-driver-plugin_3</artifactId>
        <version>3.0.3</version>
    </dependency>
  • YCSB/cassandra/src/main/java/site/ycsb/db/CassandraCQLClient.java を以下の通り編集
...

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.helpers.MessageFormatter;

import software.aws.mcs.auth.SigV4AuthProvider; ★追記

/**
 * Cassandra 2.x CQL client.
 *
 * See {@code cassandra2/README.md} for details.
 *
 * @author cmatser
 */
public class CassandraCQLClient extends DB {


...

/* ★コメントアウト
        if ((username != null) && !username.isEmpty()) {
          Cluster.Builder clusterBuilder = Cluster.builder().withCredentials(username, password)
              .withPort(Integer.valueOf(port)).addContactPoints(hosts);
          if (useSSL) {
            clusterBuilder = clusterBuilder.withSSL();
          } 
          cluster = clusterBuilder.build();
        } else {
          cluster = Cluster.builder().withPort(Integer.valueOf(port))
              .addContactPoints(hosts).build();
        }
*/
        ★追記
        Cluster.Builder clusterBuilder = Cluster.builder().withPort(Integer.valueOf(port))
            .addContactPoints(hosts).withAuthProvider(new SigV4AuthProvider("ap-northeast-1"));
        if (useSSL) {
          clusterBuilder = clusterBuilder.withSSL();
        }
        cluster = clusterBuilder.build();
  • ビルドする
$ mvn clean package