Gremlin .NET에서 IAM 인증을 사용하여 Amazon Neptune 데이터베이스에 연결
개요
이 설명서에서는 Gremlin .NET 드라이버를 사용하여 IAM 인증을 활성화하고 Signature Version 4 인증 및 AWS SDK for .NET v3를 사용하여 Amazon Neptune 데이터베이스에 연결하는 방법을 보여줍니다.
기본 연결 생성
Gremlin .NET에 연결하려면 사용자 지정 라이브러리 https://github.com/aws/amazon-neptune-gremlin-dotnet-sigv4SigV4RequestSigner 소스 파일을 사용합니다. 예제 프로젝트 설정은 https://github.com/aws/amazon-neptune-gremlin-dotnet-sigv4/tree/main/example
프로젝트 파일:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp8.0</TargetFramework> </PropertyGroup> <ItemGroup> <Compile Include="../src/SigV4RequestSigner.cs" Link="SigV4RequestSigner.cs" /> <PackageReference Include="AWSSDK.Core" Version="3.7.402.24" /> <PackageReference Include="gremlin.net" Version="3.7.3" /> </ItemGroup> </Project>
예제 프로그램:
using System; using System.Collections.Generic; using System.Net.WebSockets; using System.Linq; using System.Net.Http; using System.Security.Cryptography; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Web; using Gremlin.Net; using Gremlin.Net.Driver; using Gremlin.Net.Driver.Remote; using Gremlin.Net.Process; using Gremlin.Net.Process.Traversal; using Gremlin.Net.Structure; using static Gremlin.Net.Process.Traversal.AnonymousTraversalSource; using static Gremlin.Net.Process.Traversal.__; using static Gremlin.Net.Process.Traversal.P; using static Gremlin.Net.Process.Traversal.Order; using static Gremlin.Net.Process.Traversal.Operator; using static Gremlin.Net.Process.Traversal.Pop; using static Gremlin.Net.Process.Traversal.Scope; using static Gremlin.Net.Process.Traversal.TextP; using static Gremlin.Net.Process.Traversal.Column; using static Gremlin.Net.Process.Traversal.Direction; using static Gremlin.Net.Process.Traversal.T; using Amazon.Runtime.CredentialManagement; using Amazon.Runtime; using Amazon; using Amazon.Util; using Amazon.Neptune.Gremlin.Driver; namespace NeptuneExample { class Program { static void Main(string[] args) { /* Include your Neptune endpoint and port below. */ var neptune_host = "neptune-endpoint"; // ex: mycluster.cluster.us-east-1.neptune.amazonaws.com var neptune_port = 8182; var gremlinServer = new GremlinServer(neptune_host, neptune_port); var gremlinClient = new GremlinClient(gremlinServer, webSocketConfiguration: new SigV4RequestSigner().signRequest(neptune_host, neptune_port)); var remoteConnection = new DriverRemoteConnection(gremlinClient); var g = Traversal().WithRemote(remoteConnection); /* Example code to pull the first 5 vertices in a graph. */ Console.WriteLine("Get List of Node Labels:"); Int32 limitValue = 5; var output = g.V().Limit<Vertex>(limitValue).ToList(); foreach(var item in output) { Console.WriteLine(item); } } } }