

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

# Utilizzo dell'SDK per eseguire query OpenCypher AWS
<a name="access-graph-opencypher-sdk"></a>

Con l' AWS SDK, puoi eseguire query OpenCypher sul tuo grafico di Neptune utilizzando un linguaggio di programmazione a tua scelta. L'SDK Neptune data API (`neptunedata`nome del servizio) fornisce l'azione per inviare query [ExecuteOpenCypherQuery](https://docs.aws.amazon.com/neptune/latest/data-api/API_ExecuteOpenCypherQuery.html)OpenCypher.

È necessario eseguire questi esempi da un'istanza Amazon EC2 nello stesso cloud privato virtuale (VPC) del cluster Neptune DB o da una posizione che dispone di connettività di rete all'endpoint del cluster.

Di seguito sono disponibili collegamenti diretti alla documentazione di riferimento dell'API per il `neptunedata` servizio in ogni lingua SDK:


| Linguaggio di programmazione | Riferimento all'API neptunedata | 
| --- | --- | 
| 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/) | 

## Esempi di OpenCypher AWS SDK
<a name="access-graph-opencypher-sdk-examples"></a>

Gli esempi seguenti mostrano come configurare un `neptunedata` client, eseguire una query OpenCypher e stampare i risultati. Sostituisci *YOUR\$1NEPTUNE\$1HOST* e *YOUR\$1NEPTUNE\$1PORT* con l'endpoint e la porta del tuo cluster Neptune DB.

**Timeout lato client e riprova di configurazione**  
*Il timeout del client SDK controlla per quanto tempo il client attende una risposta.* Non controlla per quanto tempo viene eseguita la query sul server. Se il client scade prima del termine del server, la query può continuare a essere eseguita su Neptune mentre il client non ha modo di recuperare i risultati.  
[Ti consigliamo di impostare il timeout di lettura lato client su `0` (nessun timeout) o su un valore che sia almeno qualche secondo più lungo rispetto all'impostazione neptune\$1query\$1timeout lato server sul tuo cluster Neptune DB.](parameters.md#parameters-db-cluster-parameters-neptune_query_timeout) Ciò consente a Neptune di controllare il timeout delle query.  
Consigliamo inoltre di impostare il numero massimo di tentativi su `1` (nessun tentativo). Se l'SDK riprova a eseguire una query ancora in esecuzione sul server, le operazioni possono essere duplicate. Ciò è particolarmente importante per le query di mutazione, in cui un nuovo tentativo potrebbe causare scritture duplicate non intenzionali.

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

1. Segui le istruzioni di [installazione per installare Boto3](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html).

1. Crea un file denominato `openCypherExample.py` e incolla il seguente codice:

   ```
   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})
   )
   
   response = client.execute_open_cypher_query(
       openCypherQuery='MATCH (n) RETURN n LIMIT 1'
   )
   
   print(json.dumps(response['results'], indent=2))
   ```

1. Esegui l'esempio: `python openCypherExample.py`

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

1. Segui le [istruzioni di installazione](https://docs.aws.amazon.com//sdk-for-java/latest/developer-guide/setup.html) per configurare l' AWS SDK for Java.

1. Usa il codice seguente per configurare`NeptunedataClient`, eseguire una query OpenCypher e stampare il risultato:

   ```
   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.ExecuteOpenCypherQueryRequest;
   import software.amazon.awssdk.services.neptunedata.model.ExecuteOpenCypherQueryResponse;
   
   // 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();
   
   ExecuteOpenCypherQueryRequest request = ExecuteOpenCypherQueryRequest.builder()
       .openCypherQuery("MATCH (n) RETURN n LIMIT 1")
       .build();
   
   ExecuteOpenCypherQueryResponse response = client.executeOpenCypherQuery(request);
   
   System.out.println(response.results().toString());
   ```

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

1. Segui le [istruzioni di installazione](https://docs.aws.amazon.com//sdk-for-javascript/v3/developer-guide/getting-started-nodejs.html) per configurare l'SDK per. AWS JavaScript Installa il pacchetto client neptunedata:. `npm install @aws-sdk/client-neptunedata`

1. Crea un file denominato `openCypherExample.js` e incolla il seguente codice:

   ```
   import { NeptunedataClient, ExecuteOpenCypherQueryCommand } 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);
   
   const input = {
       openCypherQuery: "MATCH (n) RETURN n LIMIT 1"
   };
   
   const command = new ExecuteOpenCypherQueryCommand(input);
   const response = await client.send(command);
   
   console.log(JSON.stringify(response, null, 2));
   ```

1. Esegui l'esempio: `node openCypherExample.js`

------