AWS SDK ExecuteGremlinProfileQueryで を使用する - AWS SDK コードの例

Doc AWS SDK Examples GitHub リポジトリには、他にも SDK の例があります。 AWS

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK ExecuteGremlinProfileQueryで を使用する

次のサンプルコードは、ExecuteGremlinProfileQuery を使用する方法を説明しています。

Java
SDK for Java 2.x
注記

GitHub には、その他のリソースもあります。AWS コード例リポジトリ で全く同じ例を見つけて、設定と実行の方法を確認してください。

/** * 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(); } }
  • API の詳細については、AWS SDK for Java 2.x 「 API リファレンス」のExecuteGremlinProfileQuery」を参照してください。

Python
SDK for Python (Boto3)
注記

GitHub には、その他のリソースもあります。AWS コード例リポジトリ で全く同じ例を見つけて、設定と実行の方法を確認してください。

# 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()
  • API の詳細については、 AWS SDK for Python (Boto3) API リファレンスのExecuteGremlinProfileQuery」を参照してください。