Ada lebih banyak contoh AWS SDK yang tersedia di repo Contoh SDK AWS Doc. GitHub
Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Gunakan DeleteDBInstance dengan AWS SDK
Contoh kode berikut menunjukkan cara menggunakanDeleteDBInstance.
Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:
- Java
-
- SDK untuk Java 2.x
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode 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 untuk Python (Boto3)
-
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di Repositori Contoh Kode 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