There are more AWS SDK examples available in the AWS Doc SDK Examples
Use ExecuteGremlinProfileQuery
with an AWS SDK
The following code examples show how to use ExecuteGremlinProfileQuery
.
- Java
-
- SDK for Java 2.x
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. /** * Executes a Gremlin query against an Amazon Neptune database using the provided {@link NeptunedataClient}. * * @param client the {@link NeptunedataClient} instance to use for executing the Gremlin query */ public static void executeGremlinQuery(NeptunedataClient client) { try { System.out.println("Querying Neptune..."); ExecuteGremlinQueryRequest request = ExecuteGremlinQueryRequest.builder() .gremlinQuery("g.V().has('code', 'ANC')") .build(); ExecuteGremlinQueryResponse response = client.executeGremlinQuery(request); System.out.println("Full Response:"); System.out.println(response); // Retrieve and print the result if (response.result() != null) { System.out.println("Query Result:"); System.out.println(response.result().toString()); } else { System.out.println("No result returned from the query."); } } catch (NeptunedataException e) { System.err.println("Error calling Neptune: " + e.awsErrorDetails().errorMessage()); } catch (Exception e) { System.err.println("Unexpected error: " + e.getMessage()); } finally { client.close(); } }
-
For API details, see ExecuteGremlinProfileQuery in AWS SDK for Java 2.x API Reference.
-
- Python
-
- SDK for Python (Boto3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. # Replace this with your actual Neptune endpoint NEPTUNE_ENDPOINT = "https://[Specify Endpoint]:8182" def main(): """ Entry point of the program. Initializes the Neptune client and executes the Gremlin query. """ config = Config(connect_timeout=10, read_timeout=30, retries={'max_attempts': 3}) neptune_client = boto3.client( "neptunedata", endpoint_url=NEPTUNE_ENDPOINT, config=config ) execute_gremlin_query(neptune_client) def execute_gremlin_query(neptune_client): """ Executes a Gremlin query against an Amazon Neptune database. """ try: print("Querying Neptune...") response = neptune_client.execute_gremlin_explain_query( gremlinQuery="g.V().has('code', 'ANC')" ) print("Full Response:") print(response['output'].read().decode('UTF-8')) except ClientError as e: print(f"Error calling Neptune: {e.response['Error']['Message']}") except BotoCoreError as e: print(f"BotoCore error: {str(e)}") except Exception as e: print(f"Unexpected error: {str(e)}") if __name__ == "__main__": main()
-
For API details, see ExecuteGremlinProfileQuery in AWS SDK for Python (Boto3) API Reference.
-