Utilisation DeleteDBInstance avec un AWS SDK - AWS Exemples de code SDK

D'autres exemples de AWS SDK sont disponibles dans le référentiel AWS Doc SDK Examples GitHub .

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Utilisation DeleteDBInstance avec un AWS SDK

Les exemples de code suivants illustrent comment utiliser DeleteDBInstance.

Java
SDK pour Java 2.x
Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code 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)); }
Python
SDK pour Python (Boto3)
Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code 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