

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# AWS SDK를 사용하여 Gremlin 쿼리 실행
<a name="access-graph-gremlin-sdk"></a>

 AWS SDK를 사용하면 원하는 프로그래밍 언어를 사용하여 Neptune 그래프에 대해 Gremlin 쿼리를 실행할 수 있습니다. Neptune 데이터 API SDK(서비스 이름 `neptunedata`)는 Gremlin 쿼리를 제출하기 위한 [ExecuteGremlinQuery](https://docs.aws.amazon.com/neptune/latest/data-api/API_ExecuteGremlinQuery.html) 작업을 제공합니다.

이러한 예제는 Neptune DB 클러스터와 동일한 Virtual Private Cloud(VPC)의 Amazon EC2 인스턴스 또는 클러스터 엔드포인트에 네트워크로 연결된 위치에서 실행해야 합니다.

각 SDK 언어의 `neptunedata` 서비스에 대한 API 참조 설명서로 연결되는 직접 링크는 아래에서 확인할 수 있습니다.


| 프로그래밍 언어 | neptunedata API 참조 | 
| --- | --- | 
| C\$1\$1 | [https://sdk.amazonaws.com/cpp/api/LATEST/aws-cpp-sdk-neptunedata/html/annotated.html](https://sdk.amazonaws.com/cpp/api/LATEST/aws-cpp-sdk-neptunedata/html/annotated.html) | 
| Go | [https://docs.aws.amazon.com/sdk-for-go/api/service/neptunedata/](https://docs.aws.amazon.com/sdk-for-go/api/service/neptunedata/) | 
| Java | [https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/neptunedata/package-summary.html](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/neptunedata/package-summary.html) | 
| JavaScript | [https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-neptunedata/](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-neptunedata/) | 
| Kotlin | [https://sdk.amazonaws.com/kotlin/api/latest/neptunedata/index.html](https://sdk.amazonaws.com/kotlin/api/latest/neptunedata/index.html) | 
| .NET | [https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Neptunedata/NNeptunedata.html](https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/Neptunedata/NNeptunedata.html) | 
| PHP | [https://docs.aws.amazon.com/aws-sdk-php/v3/api/namespace-Aws.Neptunedata.html](https://docs.aws.amazon.com/aws-sdk-php/v3/api/namespace-Aws.Neptunedata.html) | 
| Python | [https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/neptunedata.html](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/neptunedata.html) | 
| Ruby | [https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Neptunedata.html](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Neptunedata.html) | 
| Rust | [https://crates.io/crates/aws-sdk-neptunedata](https://crates.io/crates/aws-sdk-neptunedata) | 
| CLI | [https://docs.aws.amazon.com/cli/latest/reference/neptunedata/](https://docs.aws.amazon.com/cli/latest/reference/neptunedata/) | 

## Gremlin AWS SDK 예제
<a name="access-graph-gremlin-sdk-examples"></a>

다음 예제에서는 `neptunedata` 클라이언트를 설정하고, Gremlin 쿼리를 실행하고, 결과를 인쇄하는 방법을 보여줍니다. *YOUR\$1NEPTUNE\$1HOST* 및 *YOUR\$1NEPTUNE\$1PORT*를 Neptune DB 클러스터의 엔드포인트 및 포트로 바꿉니다.

**클라이언트 측 제한 시간 및 재시도 구성**  
SDK 클라이언트 제한 시간은 *클라이언트*가 응답을 기다리는 시간을 제어합니다. 서버에서 쿼리가 실행되는 기간을 제어하지 않습니다. 서버가 완료되기 전에 클라이언트 시간이 초과되면 클라이언트가 결과를 검색할 방법이 없는 동안 Neptune에서 쿼리가 계속 실행될 수 있습니다.  
클라이언트 측 읽기 제한 시간을 `0` (제한 시간 없음) 또는 Neptune DB 클러스터의 서버 측 [neptune\$1query\$1timeout](parameters.md#parameters-db-cluster-parameters-neptune_query_timeout) 설정보다 몇 초 이상 긴 값으로 설정하는 것이 좋습니다. 이를 통해 Neptune은 쿼리 제한 시간을 제어할 수 있습니다.  
또한 최대 재시도 횟수를 로 설정하는 것이 좋습니다`1`(재시도 없음). SDK가 서버에서 계속 실행 중인 쿼리를 재시도하면 중복 작업이 발생할 수 있습니다. 이는 재시도로 인해 의도하지 않은 중복 쓰기가 발생할 수 있는 변형 쿼리에 특히 중요합니다.

------
#### [ Python ]

1. [설치 지침에](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html) 따라 Boto3를 설치합니다.

1. 라는 파일을 생성하고 다음 코드를 `gremlinExample.py` 붙여 넣습니다.

   ```
   import boto3
   import json
   from botocore.config import Config
   
   # Disable the client-side read timeout and retries so that
   # Neptune's server-side neptune_query_timeout controls query duration.
   client = boto3.client(
       'neptunedata',
       endpoint_url=f'https://YOUR_NEPTUNE_HOST:YOUR_NEPTUNE_PORT',
       config=Config(read_timeout=None, retries={'total_max_attempts': 1})
   )
   
   # Use the untyped GraphSON v3 serializer for a cleaner JSON response.
   response = client.execute_gremlin_query(
       gremlinQuery='g.V().limit(1)',
       serializer='application/vnd.gremlin-v3.0+json;types=false'
   )
   
   print(json.dumps(response['result'], indent=2))
   ```

1. 예제를 실행합니다. `python gremlinExample.py` 

------
#### [ Java ]

1. [설치 지침에](https://docs.aws.amazon.com//sdk-for-java/latest/developer-guide/setup.html) 따라 AWS SDK for Java를 설정합니다.

1. 다음 코드를 사용하여를 설정하고`NeptunedataClient`, Gremlin 쿼리를 실행하고, 결과를 인쇄합니다.

   ```
   import java.net.URI;
   import java.time.Duration;
   import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
   import software.amazon.awssdk.core.retry.RetryPolicy;
   import software.amazon.awssdk.services.neptunedata.NeptunedataClient;
   import software.amazon.awssdk.services.neptunedata.model.ExecuteGremlinQueryRequest;
   import software.amazon.awssdk.services.neptunedata.model.ExecuteGremlinQueryResponse;
   
   // Disable the client-side timeout and retries so that
   // Neptune's server-side neptune_query_timeout controls query duration.
   NeptunedataClient client = NeptunedataClient.builder()
       .endpointOverride(URI.create("https://YOUR_NEPTUNE_HOST:YOUR_NEPTUNE_PORT"))
       .overrideConfiguration(ClientOverrideConfiguration.builder()
           .apiCallTimeout(Duration.ZERO)
           .retryPolicy(RetryPolicy.none())
           .build())
       .build();
   
   // Use the untyped GraphSON v3 serializer for a cleaner JSON response.
   ExecuteGremlinQueryRequest request = ExecuteGremlinQueryRequest.builder()
       .gremlinQuery("g.V().limit(1)")
       .serializer("application/vnd.gremlin-v3.0+json;types=false")
       .build();
   
   ExecuteGremlinQueryResponse response = client.executeGremlinQuery(request);
   
   System.out.println(response.result().toString());
   ```

------
#### [ JavaScript ]

1. [설치 지침에](https://docs.aws.amazon.com//sdk-for-javascript/v3/developer-guide/getting-started-nodejs.html) 따라 AWS SDK for JavaScript를 설정합니다. neptunedata 클라이언트 패키지 설치: `npm install @aws-sdk/client-neptunedata`.

1. 라는 파일을 생성하고 다음 코드를 `gremlinExample.js` 붙여 넣습니다.

   ```
   import { NeptunedataClient, ExecuteGremlinQueryCommand } from "@aws-sdk/client-neptunedata";
   import { NodeHttpHandler } from "@smithy/node-http-handler";
   
   const config = {
       endpoint: "https://YOUR_NEPTUNE_HOST:YOUR_NEPTUNE_PORT",
       // Disable the client-side request timeout so that
       // Neptune's server-side neptune_query_timeout controls query duration.
       requestHandler: new NodeHttpHandler({
           requestTimeout: 0
       }),
       maxAttempts: 1
   };
   
   const client = new NeptunedataClient(config);
   
   // Use the untyped GraphSON v3 serializer for a cleaner JSON response.
   const input = {
       gremlinQuery: "g.V().limit(1)",
       serializer: "application/vnd.gremlin-v3.0+json;types=false"
   };
   
   const command = new ExecuteGremlinQueryCommand(input);
   const response = await client.send(command);
   
   console.log(JSON.stringify(response, null, 2));
   ```

1. 예제를 실행합니다. `node gremlinExample.js` 

------