RebootDBInstance 搭配 AWS SDK或 使用 CLI - Amazon Relational Database Service

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

RebootDBInstance 搭配 AWS SDK或 使用 CLI

下列程式碼範例示範如何使用 RebootDBInstance

CLI
AWS CLI

若要重新啟動資料庫執行個體

下列reboot-db-instance範例會啟動指定資料庫執行個體的重新啟動。

aws rds reboot-db-instance \ --db-instance-identifier test-mysql-instance

輸出:

{ "DBInstance": { "DBInstanceIdentifier": "test-mysql-instance", "DBInstanceClass": "db.t3.micro", "Engine": "mysql", "DBInstanceStatus": "rebooting", "MasterUsername": "admin", "Endpoint": { "Address": "test-mysql-instance.############.us-west-2.rds.amazonaws.com", "Port": 3306, "HostedZoneId": "Z1PVIF0EXAMPLE" }, ... output omitted... } }

如需詳細資訊,請參閱 Amazon RDS使用者指南 中的重新啟動資料庫執行個體

  • 如需API詳細資訊,請參閱 AWS CLI 命令參考 中的 RebootDBInstance

Java
SDK 適用於 Java 2.x
注意

還有更多 。 GitHub尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

import software.amazon.awssdk.regions.Region; import software.amazon.awssdk.services.rds.RdsClient; import software.amazon.awssdk.services.rds.model.RebootDbInstanceRequest; import software.amazon.awssdk.services.rds.model.RebootDbInstanceResponse; 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 RebootDBInstance { 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(); rebootInstance(rdsClient, dbInstanceIdentifier); rdsClient.close(); } public static void rebootInstance(RdsClient rdsClient, String dbInstanceIdentifier) { try { RebootDbInstanceRequest rebootDbInstanceRequest = RebootDbInstanceRequest.builder() .dbInstanceIdentifier(dbInstanceIdentifier) .build(); RebootDbInstanceResponse instanceResponse = rdsClient.rebootDBInstance(rebootDbInstanceRequest); System.out.print("The database " + instanceResponse.dbInstance().dbInstanceArn() + " was rebooted"); } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } } }
  • 如需API詳細資訊,請參閱AWS SDK for Java 2.x API參考 中的 RebootDBInstance

如需開發人員指南和程式碼範例的完整清單 AWS SDK,請參閱 使用此服務搭配 AWS SDK。本主題也包含有關入門的資訊,以及先前SDK版本的詳細資訊。