View a markdown version of this page

Usa DeletedBInstance con un AWS SDK o CLI - 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à.

Usa DeletedBInstance con un AWS SDK o CLI

Gli esempi di codice seguenti mostrano come utilizzare DeleteDBInstance.

Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:

.NET
SDK per .NET
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.

/// <summary> /// Delete a particular DB instance. /// </summary> /// <param name="dbInstanceIdentifier">DB instance identifier.</param> /// <returns>DB instance object.</returns> public async Task<DBInstance> DeleteDBInstance(string dbInstanceIdentifier) { var response = await _amazonRDS.DeleteDBInstanceAsync( new DeleteDBInstanceRequest() { DBInstanceIdentifier = dbInstanceIdentifier, SkipFinalSnapshot = true, DeleteAutomatedBackups = true }); return response.DBInstance; }
  • Per informazioni dettagliate sull’API, consulta DeleteDBInstance nella documentazione di riferimento dell’API AWS SDK per .NET .

C++
SDK per C++
Nota

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

Aws::Client::ClientConfiguration clientConfig; // Optional: Set to the AWS Region (overrides config file). // clientConfig.region = "us-east-1"; Aws::RDS::RDSClient client(clientConfig); Aws::RDS::Model::DeleteDBInstanceRequest request; request.SetDBInstanceIdentifier(dbInstanceIdentifier); request.SetSkipFinalSnapshot(true); request.SetDeleteAutomatedBackups(true); Aws::RDS::Model::DeleteDBInstanceOutcome outcome = client.DeleteDBInstance(request); if (outcome.IsSuccess()) { std::cout << "DB instance deletion has started." << std::endl; } else { std::cerr << "Error with RDS::DeleteDBInstance. " << outcome.GetError().GetMessage() << std::endl; result = false; }
  • Per informazioni dettagliate sull’API, consulta DeleteDBInstance nella documentazione di riferimento dell’API AWS SDK per C++ .

CLI
AWS CLI

Come eliminare un’istanza database

L’esempio delete-db-instance seguente elimina l’istanza database specificata dopo aver creato uno snapshot database finale denominato test-instance-final-snap.

aws rds delete-db-instance \ --db-instance-identifier test-instance \ --final-db-snapshot-identifier test-instance-final-snap

Output:

{ "DBInstance": { "DBInstanceIdentifier": "test-instance", "DBInstanceStatus": "deleting", ...some output truncated... } }
  • Per informazioni dettagliate sull’API, consulta DeleteDBInstance in AWS CLI Command Reference.

Go
SDK per Go V2
Nota

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

import ( "context" "errors" "log" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/service/rds" "github.com/aws/aws-sdk-go-v2/service/rds/types" ) type DbInstances struct { RdsClient *rds.Client } // DeleteInstance deletes a DB instance. func (instances *DbInstances) DeleteInstance(ctx context.Context, instanceName string) error { _, err := instances.RdsClient.DeleteDBInstance(ctx, &rds.DeleteDBInstanceInput{ DBInstanceIdentifier: aws.String(instanceName), SkipFinalSnapshot: aws.Bool(true), DeleteAutomatedBackups: aws.Bool(true), }) if err != nil { log.Printf("Couldn't delete instance %v: %v\n", instanceName, err) return err } else { return nil } }
  • Per informazioni dettagliate sull'API, consulta DeleteDBInstance nella Documentazione di riferimento delle API di AWS SDK per Go .

Java
SDK per Java 2.x
Nota

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

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rds.RdsClient; import software.amazon.awssdk.services.rds.model.DeleteDbInstanceRequest; import software.amazon.awssdk.services.rds.model.DeleteDbInstanceResponse; import software.amazon.awssdk.services.rds.model.RdsException; /** * Before running this Java V2 code example, set up your development * environment, including your credentials. * * For more information, see the following documentation topic: * * https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/get-started.html */ public class DeleteDBInstance { public static void main(String[] args) { final String usage = """ Usage: <dbInstanceIdentifier>\s Where: dbInstanceIdentifier - The database instance identifier\s """; if (args.length != 1) { System.out.println(usage); System.exit(1); } String dbInstanceIdentifier = args[0]; Region region = Region.US_WEST_2; RdsClient rdsClient = RdsClient.builder() .region(region) .build(); deleteDatabaseInstance(rdsClient, dbInstanceIdentifier); rdsClient.close(); } public static void deleteDatabaseInstance(RdsClient rdsClient, String dbInstanceIdentifier) { try { DeleteDbInstanceRequest deleteDbInstanceRequest = DeleteDbInstanceRequest.builder() .dbInstanceIdentifier(dbInstanceIdentifier) .deleteAutomatedBackups(true) .skipFinalSnapshot(true) .build(); DeleteDbInstanceResponse response = rdsClient.deleteDBInstance(deleteDbInstanceRequest); System.out.print("The status of the database is " + response.dbInstance().dbInstanceStatus()); } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } } }
  • Per informazioni dettagliate sull'API, consulta DeleteDBInstance nella Documentazione di riferimento delle API di AWS SDK for Java 2.x .

Kotlin
SDK per Kotlin
Nota

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

suspend fun deleteDatabaseInstance(dbInstanceIdentifierVal: String?) { val deleteDbInstanceRequest = DeleteDbInstanceRequest { dbInstanceIdentifier = dbInstanceIdentifierVal deleteAutomatedBackups = true skipFinalSnapshot = true } RdsClient.fromEnvironment { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.deleteDbInstance(deleteDbInstanceRequest) print("The status of the database is ${response.dbInstance?.dbInstanceStatus}") } }
  • Per informazioni dettagliate sull’API, consulta DeleteDBInstance nella documentazione di riferimento dell’API AWS SDK per Kotlin.

PHP
SDK per PHP
Nota

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

require __DIR__ . '/vendor/autoload.php'; use Aws\Exception\AwsException; //Create an RDSClient $rdsClient = new Aws\Rds\RdsClient([ 'region' => 'us-east-1' ]); $dbIdentifier = '<<{{db-identifier}}>>'; try { $result = $rdsClient->deleteDBInstance([ 'DBInstanceIdentifier' => $dbIdentifier, ]); var_dump($result); } catch (AwsException $e) { echo $e->getMessage(); echo "\n"; }
  • Per informazioni dettagliate sull’API, consulta DeleteDBInstance nella documentazione di riferimento dell’API AWS SDK per PHP .

Python
SDK per Python (Boto3)
Nota

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

class InstanceWrapper: """Encapsulates Amazon RDS DB instance actions.""" def __init__(self, rds_client): """ :param rds_client: A Boto3 Amazon RDS client. """ self.rds_client = rds_client @classmethod def from_client(cls): """ Instantiates this class from a Boto3 client. """ rds_client = boto3.client("rds") return cls(rds_client) def delete_db_instance(self, instance_id): """ Deletes a DB instance. :param instance_id: The ID of the DB instance to delete. :return: Data about the deleted DB instance. """ try: response = self.rds_client.delete_db_instance( DBInstanceIdentifier=instance_id, SkipFinalSnapshot=True, DeleteAutomatedBackups=True, ) db_inst = response["DBInstance"] except ClientError as err: logger.error( "Couldn't delete DB instance %s. Here's why: %s: %s", instance_id, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return db_inst
  • Per informazioni dettagliate sull’API, consulta DeleteDBInstance nella documentazione di riferimento dell’API AWS SDK per Python (Boto3).

Swift
SDK per Swift
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.

import AWSRDS /// Delete the specified database instance. /// /// - Parameter instanceIdentifier: The identifier of the database /// instance to delete. func deleteDBInstance(instanceIdentifier: String) async { do { _ = try await rdsClient.deleteDBInstance( input: DeleteDBInstanceInput( dbInstanceIdentifier: instanceIdentifier, deleteAutomatedBackups: true, skipFinalSnapshot: true ) ) } catch { print("*** Error deleting the database instance \(instanceIdentifier): \(error.localizedDescription)") } }
  • Per informazioni dettagliate sull’API, consulta DeleteDBInstance nella documentazione di riferimento dell’API AWS SDK per Swift.