### Install Neo4j .NET Driver (Simple) Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-opencypher-bolt.md Install the Neo4j.Driver.Simple package for .NET to make synchronous calls. This is the first step for .NET examples. ```powershell Install-Package Neo4j.Driver.Simple-4.3.0 ``` -------------------------------- ### curl Examples for Parameterized Query (POST, GET, DIRECT POST) Source: https://docs.aws.amazon.com/neptune/latest/userguide/opencypher-parameterized-queries.md Demonstrates executing parameterized openCypher queries using cURL with different methods: POST, GET (URL-encoded), and DIRECT POST. ```bash curl https://{{your-neptune-endpoint}}:{{port}}/openCypher \ -d "query=MATCH (n {name: \$name, age: \$age}) RETURN n" \ -d "parameters=\"{\"name\": \"john\", \"age\": 20}\"" ``` ```bash curl -X GET \ "https://{{your-neptune-endpoint}}:{{port}}/openCypher?query=MATCH%20%28n%20%7Bname:%24name,age:%24age%7D%29%20RETURN%20n¶meters=%7B%22name%22:%22john%22,%22age%22:20%7D" ``` ```bash curl -H "Content-Type: application/opencypher" \ "https://{{your-neptune-endpoint}}:{{port}}/openCypher?parameters=%7B%22name%22:%22john%22,%22age%22:20%7D" \ -d "MATCH (n {name: \$name, age: \$age}) RETURN n" ``` -------------------------------- ### Clone Neptune SPARQL Java SigV4 Sample Repository Source: https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-connecting-sparql-java.md Clone the sample project from GitHub to get started with IAM authentication examples for connecting to Neptune using Java. ```bash git clone https://github.com/aws/amazon-neptune-sparql-java-sigv4.git ``` -------------------------------- ### Install Neptune for GraphQL Utility Source: https://docs.aws.amazon.com/neptune/latest/userguide/tools-graphql.md Install the utility globally using NPM. Refer to the installation and setup guide for more details. ```bash npm i @aws/neptune-for-graphql -g ``` -------------------------------- ### Start Gremlin Console Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-console.md Launches the Gremlin Console from its installation directory. This command activates necessary plugins and presents the `gremlin>` prompt. ```bash bin/gremlin.sh ``` -------------------------------- ### Install Apache Web Server Source: https://docs.aws.amazon.com/neptune/latest/userguide/sparql-api-reference-update-load.md Installs Apache HTTP Server and the mod_ssl module on an Amazon Linux instance and starts the Apache service. ```bash sudo yum install httpd mod_ssl sudo /usr/sbin/apachectl start ``` -------------------------------- ### Install Java 8 on EC2 Instance Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-sparql-java.md Installs Java 8 Development Kit on an EC2 instance. This is a prerequisite for running the Neptune Java example. ```bash sudo yum install java-1.8.0-devel ``` -------------------------------- ### Example: Relationship start ID with ID space Source: https://docs.aws.amazon.com/neptune/latest/userguide/bulk-load-tutorial-format-opencypher.md Illustrates specifying an ID space for the :START_ID column in a relationship file. ```cypher :START_ID(movies) ``` -------------------------------- ### Start ML Model Transform Job (Custom Model) Source: https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-api-modeltransform.md This example demonstrates how to start a model transform job with custom model parameters using the AWS CLI, specifying the S3 directory and entry point script for the custom model. ```APIDOC ## AWS CLI: start-ml-model-transform-job (Custom Model) ### Description Starts an ML model transform job using a custom model implementation. ### Method (AWS CLI command, not a direct HTTP method) ### Endpoint (AWS CLI command, not a direct HTTP endpoint) ### Parameters - **--endpoint-url** (string) - The Neptune cluster endpoint URL. - **--id** (string) - Required - A unique identifier for the model transform job. - **--training-job-name** (string) - Required - The name of a completed SageMaker training job. - **--model-transform-output-s3-location** (string) - Required - The S3 location for the transformed data. - **--custom-model-transform-parameters** (JSON string) - Required - Parameters for the custom model transform. - **sourceS3DirectoryPath** (string) - Required - The S3 path to the directory containing the custom model's Python module. - **transformEntryPointScript** (string) - Required - The name of the entry point script in the Python module. ### Request Example ```bash aws neptunedata start-ml-model-transform-job \ --endpoint-url https://{{your-neptune-endpoint}}:{{port}} \ --id "{{(a unique model-transform job ID)}}" \ --training-job-name "{{(name of a completed SageMaker training job)}}" \ --model-transform-output-s3-location "s3://{{(your Amazon S3 bucket)}}/neptune-model-transform/" \ --custom-model-transform-parameters '{ "sourceS3DirectoryPath": "s3://{{(your Amazon S3 bucket)}}/{{(path to your Python module)}}", "transformEntryPointScript": "{{(your transform script entry-point name in the Python module)}}" }' ``` ### Response (Response details not provided in source) #### Response Example (Response example not provided in source) ``` -------------------------------- ### Start ML Model Training Job with Custom Model Source: https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-custom-model-overview.md This example demonstrates how to start a model training job using a custom model in Neptune ML via the AWS CLI. It includes the necessary parameters for specifying the custom model training configuration. ```APIDOC ## AWS CLI ```bash aws neptunedata start-ml-model-training-job \ --endpoint-url https://{{your-neptune-endpoint}}:{{port}} \ --id "{{(a unique model-training job ID)}}" \ --data-processing-job-id "{{(the data-processing job-id of a completed job)}}" \ --train-model-s3-location "s3://{{(your Amazon S3 bucket)}}/neptune-model-graph-autotrainer" \ --model-name "custom" \ --custom-model-training-parameters '{ "sourceS3DirectoryPath": "s3://{{(your Amazon S3 bucket)}}/{{(path to your Python module)}}", "trainingEntryPointScript": "{{(your training script entry-point name in the Python module)}}", "transformEntryPointScript": "{{(your transform script entry-point name in the Python module)}}" }' ``` ### Parameters for `customModelTrainingParameters`: - **`sourceS3DirectoryPath`** (string) - Required. The path to the Amazon S3 location where the Python module implementing your model is located. This must point to a valid existing Amazon S3 location that contains, at a minimum, a training script, a transform script, and a `model-hpo-configuration.json` file. - **`trainingEntryPointScript`** (string) - Optional. The name of the entry point in your module of a script that performs model training and takes hyperparameters as command-line arguments, including fixed hyperparameters. Defaults to `training.py`. - **`transformEntryPointScript`** (string) - Optional. The name of the entry point in your module of a script that should be run after the best model from the hyperparameter search has been identified, to compute the model artifacts necessary for model deployment. It should be able to run with no command-line arguments. Defaults to `transform.py`. ``` -------------------------------- ### Path Response Example Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-opencypher-queries.md Example JSON output for a path query in OpenCypher. ```json { "results": [ { "p": [ { "~id": "22", "~entityType": "node", "~labels": [ "airport" ], "~properties": { "desc": "Seattle-Tacoma", "lon": -122.30899810791, "runways": 3, "type": "airport", "country": "US", "region": "US-WA", "lat": 47.4490013122559, "elev": 432, "city": "Seattle", "icao": "KSEA", "code": "SEA", "longest": 11901 } }, { "~id": "7389", "~entityType": "relationship", "~start": "22", "~end": "151", "~type": "route", "~properties": { "dist": 956 } }, { "~id": "151", "~entityType": "node", "~labels": [ "airport" ], "~properties": { "desc": "Ontario International Airport", "lon": -117.600997924805, "runways": 2, "type": "airport", "country": "US", "region": "US-CA", "lat": 34.0559997558594, "elev": 944, "city": "Ontario", "icao": "KONT", "code": "ONT", "longest": 12198 } } ] } ] } ``` -------------------------------- ### Run the .NET sample Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-dotnet.md Execute the .NET application to connect to Neptune and run the Gremlin queries. ```bash dotnet run ``` -------------------------------- ### Create a new .NET project Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-dotnet.md Use the dotnet CLI to create a new console application project. ```bash dotnet new console -o gremlinExample ``` -------------------------------- ### Install Neo4j Python Driver Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-opencypher-bolt.md Install the Neo4j Python driver using pip. This is a prerequisite for running Python examples. ```bash python -m pip install neo4j ``` -------------------------------- ### Property-Graph Edge with Multi-Label Nodes Example Source: https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-neptune_ml-targets.md Example of specifying an edge with multi-label start and end nodes for a property-graph target. ```json "edge": [ ["Admin", Person_A"], "knows", ["Admin", "Person_B"] ] ``` -------------------------------- ### Explain Output: All Steps Converted Source: https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-explain-api.md This example shows the 'explain' output for a Gremlin query where all steps have native equivalents in Neptune. It details the original, converted, and optimized traversals. ```text ******************************************************* Neptune Gremlin Explain ******************************************************* Query String ============ g.V().out() Original Traversal ================== [GraphStep(vertex,[]), VertexStep(OUT,vertex)] Converted Traversal =================== Neptune steps: [ NeptuneGraphQueryStep(Vertex) { JoinGroupNode { PatternNode[(?1, <~label>, ?2, <~>) . project distinct ?1 .] PatternNode[(?1, ?5, ?3, ?6) . project ?1,?3 . IsEdgeIdFilter(?6) .] PatternNode[(?3, <~label>, ?4, <~>) . project ask .] }, annotations={path=[Vertex(?1):GraphStep, Vertex(?3):VertexStep], maxVarId=7} }, NeptuneTraverserConverterStep ] Optimized Traversal =================== Neptune steps: [ NeptuneGraphQueryStep(Vertex) { JoinGroupNode { PatternNode[(?1, ?5, ?3, ?6) . project ?1,?3 . IsEdgeIdFilter(?6) .], {estimatedCardinality=INFINITY} }, annotations={path=[Vertex(?1):GraphStep, Vertex(?3):VertexStep], maxVarId=7} }, NeptuneTraverserConverterStep ] Predicates ========== ``` -------------------------------- ### Property-Graph Edge Specification Example Source: https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-neptune_ml-targets.md Example of specifying an edge by its start node, edge label, and end node for a property-graph target. ```json "edge": ["Person_A", "knows", "Person_B"] ``` -------------------------------- ### Example train_instance_recommendation.json Source: https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-on-graphs-instance-selection.md This JSON file shows the recommended instance types and resource estimates for model training and transform stages. It includes recommendations for both GPU and base processing instances, along with disk and memory size estimates. ```json { "instance": "{{(the recommended instance type for model training and transform)}}", "cpu_instance": "{{(the recommended instance type for base processing instance)}}", "disk_size": "{{(the estimated disk space required)}}", "mem_size": "{{(the estimated memory required)}}" } ``` -------------------------------- ### Navigate to the project directory Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-dotnet.md Change your current directory to the newly created project folder. ```bash cd gremlinExample ``` -------------------------------- ### Example infer_instance_recommendation.json Source: https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-on-graphs-instance-selection.md This JSON file details the recommended instance type and resource estimates for an inference endpoint. It specifies the instance for inference, along with estimated disk and memory requirements. ```json { "instance" : "{{(the recommended instance type for an inference endpoint)}}", "disk_size" : "{{(the estimated disk space required)}}", "mem_size" : "{{(the estimated memory required)}}" } ``` -------------------------------- ### Start Neptune Loader Job with curl Source: https://docs.aws.amazon.com/neptune/latest/userguide/load-api-reference-load.md Use this curl command to start a Neptune data loading job. This example assumes your AWS credentials are set up in your environment. ```bash curl -X POST https://{{your-neptune-endpoint}}:{{port}}/loader \ -H 'Content-Type: application/json' \ -d '{ "source" : "s3://{{bucket-name}}/{{object-key-name}}", "format" : "opencypher", "userProvidedEdgeIds": "TRUE", "iamRoleArn" : "arn:aws:iam::{{account-id}}:role/{{role-name}}", "region" : "{{region}}", "failOnError" : "FALSE", "parallelism" : "MEDIUM" }' ``` -------------------------------- ### Multiple Graphs Specified in Request URL (GET) Source: https://docs.aws.amazon.com/neptune/latest/userguide/sparql-graph-store-protocol.md Example of a GET request where multiple graphs are specified in the request URL. Neptune will return an HTTP 400 error in this scenario. ```http GET "http://{{your-Neptune-cluster}}:{{port}}/sparql/gsp/?default&graph=urn:votes:2019" ``` -------------------------------- ### Compile and Run Java Sample with Maven Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-sparql-java.md Use this Maven command to compile and execute the Java code sample. Ensure your project is set up correctly with the necessary dependencies. ```bash mvn compile exec:java ``` -------------------------------- ### Submit Gremlin query using curl (GET) Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-rest.md This example demonstrates submitting a Gremlin query using `curl` with an HTTP GET request. The query is appended as a URL parameter. ```bash curl -G "https://{{your-neptune-endpoint}}:{{port}}?gremlin=g.V().count()" ``` -------------------------------- ### .NET OpenCypher Query Example Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-opencypher-bolt.md A .NET example demonstrating how to create and read a node in Neptune using OpenCypher queries with Bolt and IAM authentication disabled. Includes session management and transaction handling. ```csharp using Neo4j.Driver; namespace hello { // This example creates a node and reads a node in a Neptune // Cluster where IAM Authentication is not enabled. public class HelloWorldExample : IDisposable { private bool _disposed = false; private readonly IDriver _driver; private static string url = "bolt://(your cluster endpoint URL):{{(your cluster port)}}"; private static string createNodeQuery = "CREATE (a:Greeting) SET a.message = 'HelloWorldExample'"; private static string readNodeQuery = "MATCH(n:Greeting) RETURN n.message"; ~HelloWorldExample() => Dispose(false); public HelloWorldExample(string uri) { _driver = GraphDatabase.Driver(uri, AuthTokens.None, o => o.WithEncryptionLevel(EncryptionLevel.Encrypted)); } public void createNode() { // Open a session using (var session = _driver.Session()) { // Run the query in a write transaction var greeting = session.WriteTransaction(tx => { var result = tx.Run(createNodeQuery); // Consume the result return result.Consume(); }); // The output will look like this: // ResultSummary{Query=`CREATE (a:Greeting) SET a.message = 'HelloWorldExample"..... Console.WriteLine(greeting); } } public void retrieveNode() { // Open a session using (var session = _driver.Session()) { // Run the query in a read transaction var greeting = session.ReadTransaction(tx => { var result = tx.Run(readNodeQuery); // Consume the result. Read the single node // created in a previous step. return result.Single()[0].As(); }); // The output will look like this: // HelloWorldExample Console.WriteLine(greeting); } } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (_disposed) return; if (disposing) { _driver?.Dispose(); } _disposed = true; } public static void Main() { using (var apiCaller = new HelloWorldExample(url)) { apiCaller.createNode(); apiCaller.retrieveNode(); } } } } ``` -------------------------------- ### Initialize Go Module Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-go.md Initializes a new Go module for your project. This is the first step in setting up your Go environment for the Neptune connection. ```bash go mod init example.com/gremlinExample ``` -------------------------------- ### Navigate to Cloned Directory Source: https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-connecting-sparql-java.md Change the current directory to the cloned repository to access and run the sample code. ```bash cd amazon-neptune-sparql-java-sigv4 ``` -------------------------------- ### Start Model Transform Job with SDK Source: https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-api-modeltransform.md Use the AWS SDK for Python (boto3) to start a model transform job, including custom model transform parameters. Ensure you have boto3 installed and configured. ```python import boto3 from botocore.config import Config client = boto3.client( 'neptunedata', endpoint_url='https://{{your-neptune-endpoint}}:{{port}}', config=Config(read_timeout=None, retries={'total_max_attempts': 1}) ) response = client.start_ml_model_transform_job( id='{{(a unique model-transform job ID)}}', trainingJobName='{{(name of a completed SageMaker training job)}}', modelTransformOutputS3Location='s3://{{(your Amazon S3 bucket)}}/neptune-model-transform/', customModelTransformParameters={ 'sourceS3DirectoryPath': 's3://{{(your Amazon S3 bucket)}}/{{(path to your Python module)}}', 'transformEntryPointScript': '{{(your transform script entry-point name in the Python module)}}' } ) print(response) ``` -------------------------------- ### Run Apache Jena Example with IAM Authentication Source: https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-connecting-sparql-java.md Compile and execute the Apache Jena example using Maven. This command connects to your Neptune instance using Signature Version 4 authentication. Replace placeholders with your actual Neptune endpoint and port. ```bash mvn compile exec:java \ -Dexec.mainClass="com.amazonaws.neptune.client.jena.NeptuneJenaSigV4Example" \ -Dexec.args="https://{{your-neptune-endpoint}}:{{port}}" ``` -------------------------------- ### Java Example Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-opencypher-sdk.md This Java code snippet shows how to set up a NeptunedataClient, execute an OpenCypher query, and print the result, disabling client-side timeouts and retries. ```APIDOC ## Execute OpenCypher Query with Java ### Description Executes an OpenCypher query using the AWS SDK for Java, disabling client-side timeouts and retries to rely on Neptune's server-side query timeout. ### Method `client.executeOpenCypherQuery` ### Parameters #### Request Body - **openCypherQuery** (string) - Required - The OpenCypher query to execute. ### Request Example ```java 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; 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()); ``` ### Response #### Success Response (200) - **results** (string) - The results of the OpenCypher query, represented as a string. #### Response Example ``` [{"n":{"~id":"...","~label":"...",...}}] ``` ``` -------------------------------- ### Get Labels of Vertex v1 Source: https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-explain-background-indexing-examples.md This example shows how Neptune identifies the pattern and index used to retrieve the labels of a specific vertex. ```gremlin g.V('v1').label() ``` -------------------------------- ### Describe Orderable DB Instance Options Source: https://docs.aws.amazon.com/neptune/latest/userguide/api-instances.md Retrieve a list of orderable DB instance options for a specified engine. This helps in understanding available instance configurations. ```bash aws neptune describe-orderable-db-instance-options --engine neptune ``` -------------------------------- ### OpenCypher Explain Output Example Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-opencypher-explain-example-3.md This is an example of the detailed explain output for the query 'MATCH (a) RETURN DISTINCT labels(a)'. It breaks down the query execution plan, showing operators like SolutionInjection, DFESubquery, TermResolution, and DFEDistinctRelation. ```text Query: MATCH (a) RETURN DISTINCT labels(a) ╔════╤════════╤════════╤═══════════════════╤════════════════════╤═════════════════════╤══════════╤═══════════╤═══════╤═══════════╗ ║ ID │ Out #1 │ Out #2 │ Name │ Arguments │ Mode │ Units In │ Units Out │ Ratio │ Time (ms) ║ ╠════╪════════╪════════╪═══════════════════╪════════════════════╪═════════════════════╪══════════╪═══════════╪═══════╪═══════════╣ ║ 0 │ 1 │ - │ SolutionInjection │ solutions=[{}] │ - │ 0 │ 1 │ 0.00 │ 0 ║ ╟────┼────────┼────────┼───────────────────┼────────────────────┼─────────────────────┼──────────┼───────────┼───────┼───────────╢ ║ 1 │ 2 │ - │ DFESubquery │ subQuery=subQuery1 │ - │ 0 │ 5 │ 0.00 │ 81.00 ║ ╟────┼────────┼────────┼───────────────────┼────────────────────┼─────────────────────┼──────────┼───────────┼───────┼───────────╢ ║ 2 │ - │ - │ TermResolution │ vars=[?labels(a)] │ id2value_opencypher │ 5 │ 5 │ 1.00 │ 1.00 ║ ╚════╧════════╧════════╧═══════════════════╧════════════════════╧═════════════════════╧══════════╧═══════════╧═══════╧═══════════╝ ``` -------------------------------- ### Install Gremlin Python Client Source: https://docs.aws.amazon.com/neptune/latest/userguide/graph-notebooks.md Install the Gremlin Python client using pip. This is necessary for plain SageMaker AI notebooks, as Neptune notebooks include it by default. ```bash !pip install gremlinpython ``` -------------------------------- ### Python SDK Example for Getting ML Data Processing Job Status Source: https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-api-dataprocessing.md This Python code snippet demonstrates how to use the boto3 library to get the status of a Neptune ML data processing job. Ensure you have configured your AWS credentials and region. ```python import boto3 from botocore.config import Config ``` -------------------------------- ### SPARQL Prefix Query Example Source: https://docs.aws.amazon.com/neptune/latest/userguide/full-text-search-sparql-examples.md Use the 'prefix' query type to find terms that start with a specified prefix. This is useful for autocomplete-like functionality. ```sparql PREFIX foaf: PREFIX neptune-fts: SELECT * WHERE { SERVICE neptune-fts:search { neptune-fts:config neptune-fts:endpoint 'http://{{your-es-endpoint.com}}' . neptune-fts:config neptune-fts:queryType 'prefix' . neptune-fts:config neptune-fts:field foaf:name . neptune-fts:config neptune-fts:query 'mich' . neptune-fts:config neptune-fts:return ?res . } } ``` -------------------------------- ### Checkout Latest Version of Sample Project Source: https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-connecting-sparql-java.md Update your local repository to the latest version by checking out the branch corresponding to the most recent tag. ```bash git checkout $(git describe --tags `git rev-list --tags --max-count=1`) ``` -------------------------------- ### Add Vertex and Edges Source: https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-gremlin-vertex-classification-queries.md Example of adding a new vertex and connecting it with edges to existing vertices. This setup is often a prerequisite for inductive inference. ```gremlin %%gremlin g.addV('label1').property(id,'101').as('newV') .V('1').as('oldV1') .V('2').as('oldV2') .addE('eLabel1').from('newV').to('oldV1') .addE('eLabel2').from('oldV2').to('newV') ``` -------------------------------- ### Run Go Gremlin Example Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-go.md Executes the Go program to connect to Neptune and run the Gremlin traversal. This command assumes your Go file is named 'gremlinExample.go'. ```bash go run gremlinExample.go ``` -------------------------------- ### SPARQL Query Cancellation Response (Silent=False) Source: https://docs.aws.amazon.com/neptune/latest/userguide/sparql-api-status-cancel.md This is an example of the response when a SPARQL query is cancelled with `silent=false` and results have not yet started streaming. It returns a `CancelledByUserException`. ```json { "code": "CancelledByUserException", "requestId": "4d5c4fae-aa30-41cf-9e1f-91e6b7dd6f47", "detailedMessage": "Operation terminated (cancelled by user)" } ``` -------------------------------- ### Run the Python Gremlin example Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-python.md Execute the Python script to connect to Neptune and run a sample Gremlin traversal. The example prints the result of injecting a value and converting it to a list. ```bash python gremlinexample.py ``` -------------------------------- ### Get Load Job Status with curl Source: https://docs.aws.amazon.com/neptune/latest/userguide/load-api-reference-status-examples.md This example shows how to retrieve the status of a load job using the standard `curl` command. This is useful for direct API interaction. ```APIDOC ## GET /loader/{loadId} ### Description Retrieves the status and details of a specific load job. ### Method GET ### Endpoint /loader/{{loadId (a UUID)}}?details=true ### Parameters #### Query Parameters - **details** (boolean) - Optional - If true, returns detailed information about the load job. ### Request Example ```bash curl -X GET 'https://{{your-neptune-endpoint}}:{{port}}/loader/{{loadId (a UUID)}}?details=true' ``` ### Response #### Success Response (200 OK) - **status** (string) - The HTTP status of the response. - **payload** (object) - Contains the details of the load job. - **failedFeeds** (array) - List of feeds that failed during the load process. - **feedCount** (array) - Counts of feeds by status. - **overallStatus** (object) - Summary of the overall load job status. #### Response Example ```json { "status" : "200 OK", "payload" : { "failedFeeds" : [ { "datatypeMismatchErrors" : 0, "fullUri" : "s3://{{bucket}}/{{key}}", "insertErrors" : 0, "parsingErrors" : 5, "retryNumber" : 0, "runNumber" : 1, "status" : "LOAD_FAILED", "totalDuplicates" : 0, "totalRecords" : 5, "totalTimeSpent" : 3.0 } ], "feedCount" : [ { "LOAD_FAILED" : 1 } ], "overallStatus" : { "datatypeMismatchErrors" : 0, "fullUri" : "s3://{{bucket}}/{{key}}", "insertErrors" : 0, "parsingErrors" : 5, "retryNumber" : 0, "runNumber" : 1, "status" : "LOAD_FAILED", "totalDuplicates" : 0, "totalRecords" : 5, "totalTimeSpent" : 3.0 } } } ``` ``` -------------------------------- ### Get Load Job Status with awscurl Source: https://docs.aws.amazon.com/neptune/latest/userguide/load-api-reference-status-examples.md This example demonstrates how to check the status of a specific load job using the `awscurl` command-line tool. It requires AWS credentials to be configured in your environment. ```APIDOC ## GET /loader/{loadId} ### Description Retrieves the status and details of a specific load job. ### Method GET ### Endpoint /loader/{{loadId (a UUID)}}?details=true ### Parameters #### Query Parameters - **details** (boolean) - Optional - If true, returns detailed information about the load job. ### Request Example ```bash awscurl 'https://{{your-neptune-endpoint}}:{{port}}/loader/{{loadId (a UUID)}}?details=true' \ --region {{us-east-1}} \ --service neptune-db ``` ### Response #### Success Response (200 OK) - **status** (string) - The HTTP status of the response. - **payload** (object) - Contains the details of the load job. - **failedFeeds** (array) - List of feeds that failed during the load process. - **feedCount** (array) - Counts of feeds by status. - **overallStatus** (object) - Summary of the overall load job status. #### Response Example ```json { "status" : "200 OK", "payload" : { "failedFeeds" : [ { "datatypeMismatchErrors" : 0, "fullUri" : "s3://{{bucket}}/{{key}}", "insertErrors" : 0, "parsingErrors" : 5, "retryNumber" : 0, "runNumber" : 1, "status" : "LOAD_FAILED", "totalDuplicates" : 0, "totalRecords" : 5, "totalTimeSpent" : 3.0 } ], "feedCount" : [ { "LOAD_FAILED" : 1 } ], "overallStatus" : { "datatypeMismatchErrors" : 0, "fullUri" : "s3://{{bucket}}/{{key}}", "insertErrors" : 0, "parsingErrors" : 5, "retryNumber" : 0, "runNumber" : 1, "status" : "LOAD_FAILED", "totalDuplicates" : 0, "totalRecords" : 5, "totalTimeSpent" : 3.0 } } } ``` ``` -------------------------------- ### Using Neptune explain API with Neptune Workbench Source: https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-traversal-tuning.md This example shows how to use the %%gremlin explain cell magic in Neptune Workbench to pass a Gremlin query to the explain API. ```python %%gremlin explain ``` -------------------------------- ### Get Incoming Adjacent Vertices v1 (Index Not Available) Source: https://docs.aws.amazon.com/neptune/latest/userguide/gremlin-explain-background-indexing-examples.md This example highlights a query for incoming adjacent vertices that Neptune cannot process efficiently due to the absence of a reverse traversal OSGP index. ```gremlin g.V('v1').in() ``` -------------------------------- ### Update Neptune ML Model Training Job (Python SDK) Source: https://docs.aws.amazon.com/neptune/latest/userguide/machine-learning-api-modeltraining.md This Python SDK example shows how to start an incremental model training job. Include the `previousModelTrainingJobId` parameter to update an existing model. ```python import boto3 from botocore.config import Config client = boto3.client( 'neptunedata', endpoint_url='https://{{your-neptune-endpoint}}:{{port}}', config=Config(read_timeout=None, retries={'total_max_attempts': 1}) ) response = client.start_ml_model_training_job( id='{{(a unique model-training job ID)}}', dataProcessingJobId='{{(the data-processing job-id of a completed job)}}', trainModelS3Location='s3://{{(your S3 bucket)}}/neptune-model-graph-autotrainer', previousModelTrainingJobId='{{(the job ID of a completed model-training job to update)}}' ) ``` -------------------------------- ### Start RDF4J Console Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-sparql-rdf4j-console.md Navigate to the RDF4J SDK directory and run this command to start the RDF4J Console. This command initiates the REPL environment for interacting with RDF graphs. ```shell bin/console.sh ``` -------------------------------- ### IAM Policy for Read-Only Data Access in Neptune Source: https://docs.aws.amazon.com/neptune/latest/userguide/iam-data-access-examples.md This policy grants permissions for full read-only access to data within a Neptune DB cluster. It specifies actions starting with 'Read', 'Get', and 'List'. ```json { "Version":"2012-10-17", "Statement":[ { "Effect": "Allow", "Action": [ "neptune-db:Read*", "neptune-db:Get*", "neptune-db:List*" ], "Resource": "arn:aws:neptune-db:{{us-east-1}}:{{123456789012}}:{{cluster-ABCD1234EFGH5678IJKL90MNOP}}/*" } ] } ``` -------------------------------- ### Configure HTTP Proxy for Gremlin Console Source: https://docs.aws.amazon.com/neptune/latest/userguide/iam-auth-connecting-gremlin-console.md Sets system properties to configure HTTP proxy settings if the `:install` command fails due to proxy issues. Replace placeholders with your actual proxy details. ```groovy System.setProperty("https.proxyHost", "{{(the proxy IP address)}}") System.setProperty("https.proxyPort", "{{(the proxy port)}}") ``` -------------------------------- ### Bolt Protocol IAM Authentication Resource Path (Java) Source: https://docs.aws.amazon.com/neptune/latest/userguide/engine-releases-1.2.0.0.R3.md Example of setting the resource path for IAM signing when using the Bolt protocol with IAM authentication in Java. This is required starting with engine release 1.2.0.0. ```Java request.setResourcePath("/openCypher")); ``` -------------------------------- ### Generate Keystore for SSL Source: https://docs.aws.amazon.com/neptune/latest/userguide/access-graph-gremlin-java.md Use this command to generate a keystore for SSL configuration. Replace placeholders with your specific details. ```bash keytool -genkey -alias {{(host name)}} -keyalg RSA -keystore server.jks ```