使用 Amazon SDK 删除 Amazon RDS 数据库实例
以下代码示例显示了如何删除 Amazon RDS 数据库实例。
操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:
- .NET
-
- Amazon SDK for .NET
-
注意
在 GitHub 上查看更多内容。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 /// <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; }
-
有关 API 详细信息,请参阅《Amazon SDK for .NET API 参考》中的 DeleteDBInstance。
-
- C++
-
- 适用于 C++ 的 SDK
-
注意
在 GitHub 上查看更多内容。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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; }
-
有关 API 详细信息,请参阅《Amazon SDK for C++ API 参考》中的 DeleteDBInstance。
-
- Go
-
- SDK for Go V2
-
注意
在 GitHub 上查看更多内容。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 type DbInstances struct { RdsClient *rds.Client } // DeleteInstance deletes a DB instance. func (instances *DbInstances) DeleteInstance(instanceName string) error { _, err := instances.RdsClient.DeleteDBInstance(context.TODO(), &rds.DeleteDBInstanceInput{ DBInstanceIdentifier: aws.String(instanceName), SkipFinalSnapshot: true, DeleteAutomatedBackups: aws.Bool(true), }) if err != nil { log.Printf("Couldn't delete instance %v: %v\n", instanceName, err) return err } else { return nil } }
-
有关 API 详细信息,请参阅《Amazon SDK for Go API 参考》中的 DeleteDBInstance
。
-
- Java
-
- SDK for Java 2.x
-
注意
在 GitHub 上查看更多内容。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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); } }
-
有关 API 详细信息,请参阅《Amazon SDK for Java 2.x API 参考》中的 DeleteDBInstance。
-
- Kotlin
-
- SDK for Kotlin
-
注意
这是适用于预览版中功能的预发行文档。本文档随时可能更改。
注意
在 GitHub 上查看更多内容。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 suspend fun deleteDatabaseInstance(dbInstanceIdentifierVal: String?) { val deleteDbInstanceRequest = DeleteDbInstanceRequest { dbInstanceIdentifier = dbInstanceIdentifierVal deleteAutomatedBackups = true skipFinalSnapshot = true } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.deleteDbInstance(deleteDbInstanceRequest) print("The status of the database is ${response.dbInstance?.dbInstanceStatus}") } }
-
有关 API 详细信息,请参阅《Amazon SDK for Kotlin API 参考》中的 DeleteDBInstance
。
-
- Python
-
- 适用于 Python (Boto3) 的 SDK
-
注意
在 GitHub 上查看更多内容。在 Amazon 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 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
-
有关 API 详细信息,请参阅《适用于 Python 的 Amazon SDK(Boto3)API 参考》中的 DeleteDBInstance。
-
有关 Amazon 软件开发工具包开发人员指南和代码示例的完整列表,请参阅 将此服务与 Amazon SDK 结合使用。本主题还包括有关入门的信息以及有关先前的软件开发工具包版本的详细信息。