文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK DeleteDBInstance
配合使用
以下代码示例演示如何使用 DeleteDBInstance
。
- Java
-
- 适用于 Java 的 SDK 2.x
-
注意
还有更多相关信息 GitHub。在 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)); }
-
有关 API 的详细信息,请参阅DBInstance《AWS SDK for Java 2.x API 参考》中的 “删除”。
-
- Python
-
- 适用于 Python 的 SDK (Boto3)
-
注意
还有更多相关信息 GitHub。在 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
-
有关 API 的详细信息,请参阅 Python DBInstance 版AWS SDK 中删除 (Boto3) API 参考。
-
DeleteDBCluster
DeleteDBSubnetGroup