Hay más ejemplos de AWS SDK disponibles en el GitHub repositorio de ejemplos de AWS Doc SDK
Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.
Utilízalo CreateGraph
con un SDK AWS
Los siguientes ejemplos de código muestran cómo utilizar CreateGraph
.
- Java
-
- SDK para Java 2.x
-
nota
Hay más en marcha GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS
. /** * Executes the process of creating a new Neptune graph. * * @param client the Neptune graph client used to interact with the Neptune service * @param graphName the name of the graph to be created * @throws NeptuneGraphException if an error occurs while creating the graph */ public static void executeCreateGraph(NeptuneGraphClient client, String graphName) { try { // Create the graph request CreateGraphRequest request = CreateGraphRequest.builder() .graphName(graphName) .provisionedMemory(16) .build(); // Create the graph CreateGraphResponse response = client.createGraph(request); // Extract the graph name and ARN String createdGraphName = response.name(); String graphArn = response.arn(); String graphEndpoint = response.endpoint(); System.out.println("Graph created successfully!"); System.out.println("Graph Name: " + createdGraphName); System.out.println("Graph ARN: " + graphArn); System.out.println("Graph Endpoint: " +graphEndpoint ); } catch (NeptuneGraphException e) { System.err.println("Failed to create graph: " + e.awsErrorDetails().errorMessage()); } finally { client.close(); } }
-
Para obtener más información sobre la API, consulta CreateGraphla Referencia AWS SDK for Java 2.x de la API.
-
- Python
-
- SDK para Python (Boto3)
-
nota
Hay más información al respecto GitHub. Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS
. """ Running this example. ---------------------------------------------------------------------------------- VPC Networking Requirement: ---------------------------------------------------------------------------------- Amazon Neptune must be accessed from **within the same VPC** as the Neptune cluster. It does not expose a public endpoint, so this code must be executed from: - An **AWS Lambda function** configured to run inside the same VPC - An **EC2 instance** or **ECS task** running in the same VPC - A connected environment such as a **VPN**, **AWS Direct Connect**, or a **peered VPC** """ GRAPH_NAME = "sample-analytics-graph" def main(): config = Config(retries={"total_max_attempts": 1, "mode": "standard"}, read_timeout=None) client = boto3.client("neptune-graph", config=config) execute_create_graph(client, GRAPH_NAME) def execute_create_graph(client, graph_name): try: print("Creating Neptune graph...") response = client.create_graph( graphName=graph_name, provisionedMemory = 16 ) created_graph_name = response.get("name") graph_arn = response.get("arn") graph_endpoint = response.get("endpoint") print("Graph created successfully!") print(f"Graph Name: {created_graph_name}") print(f"Graph ARN: {graph_arn}") print(f"Graph Endpoint: {graph_endpoint}") except ClientError as e: print(f"Failed to create graph: {e.response['Error']['Message']}") except BotoCoreError as e: print(f"Failed to create graph: {str(e)}") except Exception as e: print(f"Unexpected error: {str(e)}") if __name__ == "__main__": main()
-
Para obtener más información sobre la API, consulta CreateGraphla AWS Referencia de API de SDK for Python (Boto3).
-