Gunakan RebootDBInstance dengan AWS SDK atau CLI - AWS SDKContoh Kode

Ada lebih banyak AWS SDK contoh yang tersedia di GitHub repo SDKContoh AWS Dokumen.

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan RebootDBInstance dengan AWS SDK atau CLI

Contoh kode berikut menunjukkan cara menggunakanRebootDBInstance.

CLI
AWS CLI

Untuk me-reboot instance DB

reboot-db-instanceContoh berikut memulai reboot dari instance DB yang ditentukan.

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

Output:

{ "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... } }

Untuk informasi selengkapnya, lihat Mem-boot Ulang Instans DB di RDSPanduan Pengguna Amazon.

Java
SDKuntuk Java 2.x
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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); } } }