本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 Cassandra Perl 用戶端驅動程式以程式設計方式存取 Amazon Keyspaces
本節說明如何使用 Perl 用戶端驅動程式連線至 Amazon Keyspaces。對於此程式碼範例,我們使用 Perl 5。Amazon Keyspaces 需要使用 Transport Layer Security (TLS) 來協助保護與用戶端的連線。
重要
Amazon Keyspacescertificates 正在轉換至 Amazon Trust Services (ATS) 階層。確保您的環境信任 Amazon 根 CAs1–4,以避免在此輪換期間發生連線錯誤。Perl 驅動程式不會驗證伺服器的 Amazon SSL 憑證,這表示您無法確認您連線到 Amazon Keyspaces。第二個步驟是設定驅動程式在連線至 Amazon Keyspaces 時使用 TLS,並確保用戶端和伺服器之間傳輸的資料已加密。
-
從 下載 Cassandra DBI 驅動程式,https://metacpan.org/pod/DBD::Cassandra
並將驅動程式安裝到您的 Perl 環境。確切的步驟取決於環境。以下是常見的範例。 cpanm DBD::Cassandra -
為您的應用程式建立 檔案。
touch cqlapp.pl -
將下列範例程式碼新增至 cqlapp.pl 檔案。
use DBI; my $user = "ServiceUserName"; my $password = "ServicePassword"; my $db = DBI->connect("dbi:Cassandra:host=cassandra.us-east-2.amazonaws.com;port=9142;tls=1;", $user, $password); my $rows = $db->selectall_arrayref("select * from system_schema.keyspaces"); print "Found the following Keyspaces...\n"; for my $row (@$rows) { print join(" ",@$row['keyspace_name']),"\n"; } $db->disconnect;重要
依照 的步驟,確定
ServiceUserName和ServicePassword與您產生服務特定登入資料時取得的使用者名稱和密碼相符建立服務特定的登入資料,以程式設計方式存取 Amazon Keyspaces。注意
如需可用端點的清單,請參閱 Amazon Keyspaces 的服務端點。
執行應用程式。
perl cqlapp.pl