기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
Cassandra. NET Core 클라이언트 드라이버를 사용하여 프로그래밍 방식으로 Amazon Keyspaces에 액세스
이 섹션에서는 .NET Core 클라이언트 드라이버를 사용하여 Amazon Keyspaces에 접속하는 방법을 소개합니다. 설정 단계는 환경 및 운영 체제에 따라 다르므로 그에 따라 수정해야 할 수도 있습니다. Amazon Keyspaces에서는 클라이언트와의 연결을 보호하는 데 도움이 되는 전송 계층 보안(TLS)을 사용해야 합니다. TLS를 사용하여 Amazon Keyspace에 접속하려면 Starfield 디지털 인증서를 다운로드하고 TLS를 사용하도록 드라이버를 구성해야 합니다.
-
Starfield 인증서를 다운로드하고 로컬 디렉터리에 저장한 다음 경로를 기록해 둡니다. 다음은 PowerShell을 사용하는 예제입니다.
$client = new-object System.Net.WebClient $client.DownloadFile("https://certs.secureserver.net/repository/sf-class2-root.crt","
path_to_file
\sf-class2-root.crt") -
너겟 콘솔을 사용하여 너겟을 통해 CassandraCSharpDriver를 설치합니다.
PM> Install-Package CassandraCSharpDriver
-
다음 예제는.NET Core C# 콘솔 프로젝트를 사용하여 Amazon Keyspaces에 접속하고 쿼리를 실행합니다.
using Cassandra; using System; using System.Collections.Generic; using System.Linq; using System.Net.Security; using System.Runtime.ConstrainedExecution; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace CSharpKeyspacesExample { class Program { public Program(){} static void Main(string[] args) { X509Certificate2Collection certCollection = new X509Certificate2Collection(); X509Certificate2 amazoncert = new X509Certificate2(@"
path_to_file
\sf-class2-root.crt"); var userName = "ServiceUserName
"; var pwd = "ServicePassword
"; certCollection.Add(amazoncert); var awsEndpoint = "cassandra.us-east-2.amazonaws.com
" ; var cluster = Cluster.Builder() .AddContactPoints(awsEndpoint) .WithPort(9142) .WithAuthProvider(new PlainTextAuthProvider(userName, pwd)) .WithSSL(new SSLOptions().SetCertificateCollection(certCollection)) .Build(); var session = cluster.Connect(); var rs = session.Execute("SELECT * FROM system_schema.tables;"); foreach (var row in rs) { var name = row.GetValue<String>("keyspace_name"); Console.WriteLine(name); } } } }사용 노트:
"
을 첫 번째 단계에서 저장한 인증서 경로로 바꿉니다.path_to_file
/sf-class2-root.crt"ServiceUserName
과ServicePassword
는 Amazon Keyspaces에 프로그래밍 방식으로 액세스하기 위한 서비스별 자격 증명 만들기에 대한 단계에 따라 서비스별 자격 증명을 생성할 때 얻은 사용자 이름 및 암호와 일치해야 합니다.사용 가능한 엔드포인트 목록은 Amazon Keyspaces의 서비스 엔드포인트 섹션을 참조하세요.