Utilizzare con un SDK DeleteDBInstanceAWS - AWS Esempi di codice SDK

Sono disponibili altri esempi AWS SDK nel repository AWS Doc SDK Examples. GitHub

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à.

Utilizzare con un SDK DeleteDBInstanceAWS

Gli esempi di codice seguenti mostrano come utilizzare DeleteDBInstance.

Java
SDK per Java 2.x
Nota

C'è altro da fare. GitHub Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

/** * Deletes a DB instance asynchronously. * * @param instanceId the identifier of the DB instance to be deleted * @return a {@link CompletableFuture} that completes when the DB instance has been deleted */ public CompletableFuture<Void> deleteDBInstanceAsync(String instanceId) { DeleteDbInstanceRequest request = DeleteDbInstanceRequest.builder() .dbInstanceIdentifier(instanceId) .skipFinalSnapshot(true) .build(); return getAsyncClient().deleteDBInstance(request) .thenAccept(response -> System.out.println("🗑️ Deleting DB Instance: " + instanceId)); }
  • Per i dettagli sull'API, consulta Delete DBInstance in AWS SDK for Java 2.x API Reference.

Python
SDK per Python (Boto3)
Nota

C'è altro su GitHub. Trova l'esempio completo e scopri di più sulla configurazione e l'esecuzione nel Repository di esempi di codice AWS.

def delete_db_instance(neptune_client, instance_id: str): """ Deletes a Neptune DB instance and waits for its deletion to complete. Raises exception to be handled by calling code. """ print(f"Initiating deletion of DB Instance: {instance_id}") try: neptune_client.delete_db_instance( DBInstanceIdentifier=instance_id, SkipFinalSnapshot=True ) print(f"Waiting for DB Instance '{instance_id}' to be deleted...") waiter = neptune_client.get_waiter('db_instance_deleted') waiter.wait( DBInstanceIdentifier=instance_id, WaiterConfig={ 'Delay': 30, 'MaxAttempts': 40 } ) print(f"DB Instance '{instance_id}' successfully deleted.") except ClientError as err: code = err.response["Error"]["Code"] message = err.response["Error"]["Message"] if code == "DBInstanceNotFoundFault": print(f"Instance '{instance_id}' not found or already deleted.") elif code == "AccessDeniedException": print("Access denied. Please ensure you have the necessary permissions.") else: print(f"Couldn't delete DB instance. {code}: {message}") raise
  • Per i dettagli sull'API, consulta Delete DBInstance in AWS SDK for Python (Boto3) API Reference.