ablog

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

Amazon KeySpaces で VPC エンドポイントを使用した場合の system.peers のエントリの違い

結論

  • VPC エンドポイントを使用すると、system.peers は AZ の数に依存する。
    • パブリックエンドポイントの場合の 9 から VPCエンドポイントを使用すると 2-5 に減るが、CQL のスループット(QPS)限界が小さくなるわけではない。ただし、VPC エンドポイントを使う場合はスループットを上げるためにアプリからの接続数を増やす必要がある。

プライベート VPC エンドポイントを介して接続する場合、使用可能なエンドポイントは 9 個未満であることがほとんどです。さらに、VPC エンドポイントの数は、アベイラビリティーゾーンの数と、割り当てられた VPC 内のサブネットの数に基づいて、リージョンごとに異なる場合があります。米国東部 (バージニア北部) リージョンには 5 つのアベイラビリティーゾーンがあり、最大 5 つの Amazon Keyspaces エンドポイントを設定できます。米国西部 (北カリフォルニア) リージョンには 2 つのアベイラビリティーゾーンがあり、最大 2 つの Amazon Keyspaces エンドポイントを持つことができます

Amazon Keyspaces へのクライアントドライバー接続 (Apache Cassandra 用) - Amazon Keyspaces (Apache Cassandra 向け)

別のエンドポイントを使用してプライベート VPC エンドポイントから Amazon Keyspaces にアクセスする場合AWS アカウント、Amazon Keyspaces エンドポイントは 1 つしか表示されない可能性があります。繰り返しますが、これは Amazon Keyspaces へのスループットの規模には影響しませんが、ドライバー設定の接続数を増やす必要がある場合があります。この例では、使用可能な 1 つのエンドポイントについて同じ計算を行っています。

Amazon Keyspaces へのクライアントドライバー接続 (Apache Cassandra 用) - Amazon Keyspaces (Apache Cassandra 向け)
  • VPC エンドポイントを使用する場合、SigV4 認証しないと system.peers のエントリが空になる。
    • EC2 に IAM 権限をアタッチしても、KeySpaces にパスワード認証すると IAM で認証していないため
    • cassandra.ap-northeast-1.amazonaws.com については上記の通りだが、VPC エンドポイントの DNS 名 vpce-********.cassandra.ap-northeast-1.vpce.amazonaws.com に接続すると system.peers にエントリが表示される。

To look up and store available interface VPC endpoints in the system.peers table, Amazon Keyspaces requires that you grant the IAM entity used to connect to Amazon Keyspaces access permissions to query your VPC for the endpoint and network interface information.

Using Amazon Keyspaces with interface VPC endpoints - Amazon Keyspaces (for Apache Cassandra)

検証結果

  • VPC エンドポイントがないと system.peers に 9 つのエントリが表示される。
$  cqlsh cassandra.ap-northeast-1.amazonaws.com 9142 --ssl
Connected to Amazon Keyspaces at cassandra.ap-northeast-1.amazonaws.com:9142
[cqlsh 6.1.0 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> select * from  system.peers;

 peer           | data_center    | host_id                              | preferred_ip   | rack           | release_version | rpc_address    | schema_version                       | tokens
----------------+----------------+--------------------------------------+----------------+----------------+-----------------+----------------+--------------------------------------+--------------------------
 18.177.156.237 | ap-northeast-1 | 7afb0ca0-cfef-3ab4-a9d8-8919c468a586 | 18.177.156.237 | ap-northeast-1 |          3.11.2 | 18.177.156.237 | 05deae2d-6405-494d-a965-c0e5836bcb3c | {'-7173733806442603407'}
 18.177.156.232 | ap-northeast-1 | 0984ca2e-8ee7-397b-88a0-7d8783efd305 | 18.177.156.232 | ap-northeast-1 |          3.11.2 | 18.177.156.232 | 05deae2d-6405-494d-a965-c0e5836bcb3c | {'-5124095576030431006'}
 18.177.156.200 | ap-northeast-1 | 0dde4e04-6c73-3afb-b93c-2f5e12a441f3 | 18.177.156.200 | ap-northeast-1 |          3.11.2 | 18.177.156.200 | 05deae2d-6405-494d-a965-c0e5836bcb3c | {'-3074457345618258605'}
 18.177.156.231 | ap-northeast-1 | 33d42b23-cc2c-3460-9646-b4bffedf646f | 18.177.156.231 | ap-northeast-1 |          3.11.2 | 18.177.156.231 | 05deae2d-6405-494d-a965-c0e5836bcb3c | {'-1024819115206086204'}
 18.177.156.213 | ap-northeast-1 | 01290fa4-e20f-3fb4-ace4-7406d48c52b3 | 18.177.156.213 | ap-northeast-1 |          3.11.2 | 18.177.156.213 | 05deae2d-6405-494d-a965-c0e5836bcb3c |  {'1024819115206086197'}
 18.177.156.253 | ap-northeast-1 | def25f13-8435-31b6-b250-c900fe4785aa | 18.177.156.253 | ap-northeast-1 |          3.11.2 | 18.177.156.253 | 05deae2d-6405-494d-a965-c0e5836bcb3c |  {'3074457345618258598'}
 18.177.156.214 | ap-northeast-1 | 49074ce2-2f74-36bd-8ed4-54568cc53079 | 18.177.156.214 | ap-northeast-1 |          3.11.2 | 18.177.156.214 | 05deae2d-6405-494d-a965-c0e5836bcb3c |  {'5124095576030430999'}
 18.177.156.212 | ap-northeast-1 | 7dacf8a2-b751-3494-9062-327c622e645c | 18.177.156.212 | ap-northeast-1 |          3.11.2 | 18.177.156.212 | 05deae2d-6405-494d-a965-c0e5836bcb3c |  {'7173733806442603400'}
 18.177.156.192 | ap-northeast-1 | 973a0ad2-4c73-360e-9928-732d864bced6 | 18.177.156.192 | ap-northeast-1 |          3.11.2 | 18.177.156.192 | 05deae2d-6405-494d-a965-c0e5836bcb3c |  {'9223372036854775801'}

(9 rows)
  • VPC エンドポイントがあると AZ 数分のエントリが表示される。
    • 2 AZ(サブネット)から 3 AZ(サブネット)に増やすとエントリ数が増える。
$  cqlsh cassandra.ap-northeast-1.amazonaws.com 9142 --ssl
Connected to Amazon Keyspaces at cassandra.ap-northeast-1.amazonaws.com:9142
[cqlsh 6.1.0 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> select * from  system.peers;

 peer         | data_center    | host_id                              | preferred_ip | rack           | release_version | rpc_address  | schema_version                       | tokens
--------------+----------------+--------------------------------------+--------------+----------------+-----------------+--------------+--------------------------------------+-------------------------
 172.31.27.50 | ap-northeast-1 | fd6026af-497c-3bf5-8eb2-6369591daa2b | 172.31.27.50 | ap-northeast-1 |          3.11.2 | 172.31.27.50 | 05deae2d-6405-494d-a965-c0e5836bcb3c |                  {'-1'}
 172.31.2.222 | ap-northeast-1 | 6f997ca5-e120-390b-a657-1449de9a3005 | 172.31.2.222 | ap-northeast-1 |          3.11.2 | 172.31.2.222 | 05deae2d-6405-494d-a965-c0e5836bcb3c | {'9223372036854775806'}

(2 rows)
$  cqlsh cassandra.ap-northeast-1.amazonaws.com 9142 --ssl
Connected to Amazon Keyspaces at cassandra.ap-northeast-1.amazonaws.com:9142
[cqlsh 6.1.0 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> select * from  system.peers;

 peer          | data_center    | host_id                              | preferred_ip  | rack           | release_version | rpc_address   | schema_version                       | tokens
---------------+----------------+--------------------------------------+---------------+----------------+-----------------+---------------+--------------------------------------+--------------------------
  172.31.3.159 | ap-northeast-1 | caaf4736-f9c8-3eb5-8c7d-aada28a89452 |  172.31.3.159 | ap-northeast-1 |          3.11.2 |  172.31.3.159 | 05deae2d-6405-494d-a965-c0e5836bcb3c | {'-3074457345618258603'}
 172.31.30.103 | ap-northeast-1 | 76a77963-9462-30e7-89f2-dbb975ec5fbf | 172.31.30.103 | ap-northeast-1 |          3.11.2 | 172.31.30.103 | 05deae2d-6405-494d-a965-c0e5836bcb3c |  {'3074457345618258602'}
 172.31.46.196 | ap-northeast-1 | 90ab788e-055a-3799-a5e6-1c682d38e7ab | 172.31.46.196 | ap-northeast-1 |          3.11.2 | 172.31.46.196 | 05deae2d-6405-494d-a965-c0e5836bcb3c |  {'9223372036854775807'}

(3 rows)
  • VPC エンドポイントがある場合、preferred_ip は各サブネットの範囲内の IP アドレスになる。
$  cqlsh cassandra.ap-northeast-1.amazonaws.com 9142 --ssl
Connected to Amazon Keyspaces at cassandra.ap-northeast-1.amazonaws.com:9142
[cqlsh 6.1.0 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> select * from  system.peers;

 peer         | data_center    | host_id                              | preferred_ip | rack           | release_version | rpc_address  | schema_version                       | tokens
--------------+----------------+--------------------------------------+--------------+----------------+-----------------+--------------+--------------------------------------+-------------------------
 172.31.2.222 | ap-northeast-1 | 6f997ca5-e120-390b-a657-1449de9a3005 | 172.31.2.222 | ap-northeast-1 |          3.11.2 | 172.31.2.222 | 05deae2d-6405-494d-a965-c0e5836bcb3c |                  {'-1'}
 172.31.27.50 | ap-northeast-1 | fd6026af-497c-3bf5-8eb2-6369591daa2b | 172.31.27.50 | ap-northeast-1 |          3.11.2 | 172.31.27.50 | 05deae2d-6405-494d-a965-c0e5836bcb3c | {'9223372036854775806'}

(2 rows)

$ dig +short vpce-0611********6q73ju.cassandra.ap-northeast-1.vpce.amazonaws.com
172.31.27.50
172.31.2.222

  • VPC エンドポイントがある場合、IAM 権限がないと system.peers が空になる(SigV4認証)
$  cqlsh cassandra.ap-northeast-1.amazonaws.com 9142 --ssl
Connected to Amazon Keyspaces at cassandra.ap-northeast-1.amazonaws.com:9142
[cqlsh 6.1.0 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> select * from  system.peers;

 peer | data_center | host_id | preferred_ip | rack | release_version | rpc_address | schema_version | tokens
------+-------------+---------+--------------+------+-----------------+-------------+----------------+--------

(0 rows)
  • VPC エンドポイントがある場合、IAM 権限があると system.peers にエントリが表示される(SigV4認証)
$  cqlsh cassandra.ap-northeast-1.amazonaws.com 9142 --ssl
Connected to Amazon Keyspaces at cassandra.ap-northeast-1.amazonaws.com:9142
[cqlsh 6.1.0 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh> select * from  system.peers;

 peer         | data_center    | host_id                              | preferred_ip | rack           | release_version | rpc_address  | schema_version                       | tokens
--------------+----------------+--------------------------------------+--------------+----------------+-----------------+--------------+--------------------------------------+-------------------------
 172.31.27.50 | ap-northeast-1 | fd6026af-497c-3bf5-8eb2-6369591daa2b | 172.31.27.50 | ap-northeast-1 |          3.11.2 | 172.31.27.50 | 05deae2d-6405-494d-a965-c0e5836bcb3c |                  {'-1'}
 172.31.2.222 | ap-northeast-1 | 6f997ca5-e120-390b-a657-1449de9a3005 | 172.31.2.222 | ap-northeast-1 |          3.11.2 | 172.31.2.222 | 05deae2d-6405-494d-a965-c0e5836bcb3c | {'9223372036854775806'}

(2 rows)
  • VPC エンドポイントがある場合、IAM 権限があっても system.peers にエントリが表示されない(パスワード認証)
$ cqlsh cassandra.ap-northeast-1.amazonaws.com 9142 -u "keyspaces_user+1-at-********" -p "********" --ssl
/home/ec2-user/.local/bin/cqlsh:460: DeprecationWarning: Legacy execution parameters will be removed in 4.0. Consider using execution profiles.
/home/ec2-user/.local/bin/cqlsh:460: DeprecationWarning: Using ssl_options without ssl_context is deprecated and will result in an error in the next major release. Please use ssl_context to prepare for that release.
/home/ec2-user/.local/bin/cqlsh:490: DeprecationWarning: Setting the consistency level at the session level will be removed in 4.0. Consider using execution profiles and setting the desired consistency level to the EXEC_PROFILE_DEFAULT profile.
Connected to Amazon Keyspaces at cassandra.ap-northeast-1.amazonaws.com:9142
[cqlsh 6.0.0 | Cassandra 3.11.2 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
keyspaces_user+1-at-542203247656@cqlsh> select * from  system.peers;

 peer | data_center | host_id | preferred_ip | rack | release_version | rpc_address | schema_version | tokens
------+-------------+---------+--------------+------+-----------------+-------------+----------------+--------

(0 rows)

補足

VPC エンドポイント作成手順
  • マネジメントコンソールから [VPC]-[エンドポイント]-[エンドポイントを作成]
    • サービスカテゴリ: AWS サービス
    • サービス名: com.amazonaws.ap-northeast-1.cassandra
    • 追加設定
      • DNS 名を有効化: チェック
EC2 に以下の IAM 権限を持つ IAM ロールをアタッチする
{
   "Version":"2012-10-17",
   "Statement":[
      {
         "Sid":"ListVPCEndpoints",
         "Effect":"Allow",
         "Action":[
            "ec2:DescribeNetworkInterfaces",
            "ec2:DescribeVpcEndpoints"
         ],
         "Resource":"*"
      }
   ]
}

参考

パブリックエンドポイント経由で接続している場合、利用可能なエンドポイントは 9 つあります。VPC エンドポイントを使用している場合は、リージョンに応じて 2 ~ 5 つのエンドポイントを使用できます。

Amazon Keyspaces へのクライアントドライバー接続 (Apache Cassandra 用) - Amazon Keyspaces (Apache Cassandra 向け)

別のエンドポイントを使用してプライベート VPC エンドポイントから Amazon Keyspaces にアクセスする場合AWS アカウント、Amazon Keyspaces エンドポイントは 1 つしか表示されない可能性があります。繰り返しますが、これは Amazon Keyspaces へのスループットの規模には影響しませんが、ドライバー設定の接続数を増やす必要がある場合があります。この例では、使用可能な 1 つのエンドポイントについて同じ計算を行っています。

Amazon Keyspaces へのクライアントドライバー接続 (Apache Cassandra 用) - Amazon Keyspaces (Apache Cassandra 向け)