기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
이 섹션에서는를 사용하여 Amazon Keyspaces에 연결하는 방법을 보여줍니다.NET 코어 클라이언트 드라이버. 설정 단계는 환경 및 운영 체제에 따라 다르므로 그에 따라 수정해야 할 수도 있습니다. Amazon Keyspaces는 클라이언트와의 연결을 보호하기 위해 전송 계층 보안(TLS)을 사용해야 합니다. 를 사용하여 Amazon Keyspaces에 연결하려면 Starfield 디지털 인증서를 다운로드하고를 사용하도록 드라이버를 구성TLS해야 합니다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") -
너겟 콘솔을 사용하여 너겟을 통해 C assandraCSharp드라이버를 설치합니다.
PM> Install-Package CassandraCSharpDriver
-
다음 예제에서는를 사용합니다.NET Amazon Keyspaces에 연결하고 쿼리를 실행하는 Core C# 콘솔 프로젝트입니다.
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의 서비스 엔드포인트 섹션을 참조하세요.