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 ModifyDBInstance
dengan AWS SDK atau CLI
Contoh kode berikut menunjukkan cara menggunakanModifyDBInstance
.
- CLI
-
- AWS CLI
-
Contoh 1: Untuk memodifikasi instans DB
modify-db-instance
Contoh berikut mengaitkan grup opsi dan grup parameter dengan instance Microsoft SQL Server DB yang kompatibel.--apply-immediately
Parameter menyebabkan grup opsi dan parameter segera dikaitkan, alih-alih menunggu hingga jendela pemeliharaan berikutnya.aws rds modify-db-instance \ --db-instance-identifier
database-2
\ --option-group-nametest-se-2017
\ --db-parameter-group-nametest-sqlserver-se-2017
\ --apply-immediatelyOutput:
{ "DBInstance": { "DBInstanceIdentifier": "database-2", "DBInstanceClass": "db.r4.large", "Engine": "sqlserver-se", "DBInstanceStatus": "available", ...output omitted... "DBParameterGroups": [ { "DBParameterGroupName": "test-sqlserver-se-2017", "ParameterApplyStatus": "applying" } ], "AvailabilityZone": "us-west-2d", ...output omitted... "MultiAZ": true, "EngineVersion": "14.00.3281.6.v1", "AutoMinorVersionUpgrade": false, "ReadReplicaDBInstanceIdentifiers": [], "LicenseModel": "license-included", "OptionGroupMemberships": [ { "OptionGroupName": "test-se-2017", "Status": "pending-apply" } ], "CharacterSetName": "SQL_Latin1_General_CP1_CI_AS", "SecondaryAvailabilityZone": "us-west-2c", "PubliclyAccessible": true, "StorageType": "gp2", ...output omitted... "DeletionProtection": false, "AssociatedRoles": [], "MaxAllocatedStorage": 1000 } }
Untuk informasi selengkapnya, lihat Memodifikasi Instans Amazon RDS DB di Panduan RDS Pengguna Amazon.
Contoh 2: Untuk mengaitkan grup VPC keamanan dengan instans DB
modify-db-instance
Contoh berikut mengaitkan grup VPC keamanan tertentu dan menghapus grup keamanan DB dari instans DB:aws rds modify-db-instance \ --db-instance-identifier
dbName
\ --vpc-security-group-idssg-ID
Output:
{ "DBInstance": { "DBInstanceIdentifier": "dbName", "DBInstanceClass": "db.t3.micro", "Engine": "mysql", "DBInstanceStatus": "available", "MasterUsername": "admin", "Endpoint": { "Address": "dbName.abcdefghijk.us-west-2.rds.amazonaws.com", "Port": 3306, "HostedZoneId": "ABCDEFGHIJK1234" }, "AllocatedStorage": 20, "InstanceCreateTime": "2024-02-15T00:37:58.793000+00:00", "PreferredBackupWindow": "11:57-12:27", "BackupRetentionPeriod": 7, "DBSecurityGroups": [], "VpcSecurityGroups": [ { "VpcSecurityGroupId": "sg-ID", "Status": "active" } ], ... output omitted ... "MultiAZ": false, "EngineVersion": "8.0.35", "AutoMinorVersionUpgrade": true, "ReadReplicaDBInstanceIdentifiers": [], "LicenseModel": "general-public-license", ... output ommited ... } }
Untuk informasi selengkapnya, lihat Mengontrol akses dengan grup keamanan di Panduan RDS Pengguna Amazon.
-
Untuk API detailnya, lihat M odifyDBInstance
di Referensi AWS CLI Perintah.
-
- 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.ModifyDbInstanceRequest; import software.amazon.awssdk.services.rds.model.ModifyDbInstanceResponse; 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 ModifyDBInstance { public static void main(String[] args) { final String usage = """ Usage: <dbInstanceIdentifier> <dbSnapshotIdentifier>\s Where: dbInstanceIdentifier - The database instance identifier.\s masterUserPassword - The updated password that corresponds to the master user name.\s """; if (args.length != 2) { System.out.println(usage); System.exit(1); } String dbInstanceIdentifier = args[0]; String masterUserPassword = args[1]; Region region = Region.US_WEST_2; RdsClient rdsClient = RdsClient.builder() .region(region) .build(); updateIntance(rdsClient, dbInstanceIdentifier, masterUserPassword); rdsClient.close(); } public static void updateIntance(RdsClient rdsClient, String dbInstanceIdentifier, String masterUserPassword) { try { // For a demo - modify the DB instance by modifying the master password. ModifyDbInstanceRequest modifyDbInstanceRequest = ModifyDbInstanceRequest.builder() .dbInstanceIdentifier(dbInstanceIdentifier) .publiclyAccessible(true) .masterUserPassword(masterUserPassword) .build(); ModifyDbInstanceResponse instanceResponse = rdsClient.modifyDBInstance(modifyDbInstanceRequest); System.out.print("The ARN of the modified database is: " + instanceResponse.dbInstance().dbInstanceArn()); } catch (RdsException e) { System.out.println(e.getLocalizedMessage()); System.exit(1); } } }
-
Untuk API detailnya, lihat M odifyDBInstance di AWS SDK for Java 2.x APIReferensi.
-
- Kotlin
-
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun updateIntance( dbInstanceIdentifierVal: String?, masterUserPasswordVal: String?, ) { val request = ModifyDbInstanceRequest { dbInstanceIdentifier = dbInstanceIdentifierVal publiclyAccessible = true masterUserPassword = masterUserPasswordVal } RdsClient { region = "us-west-2" }.use { rdsClient -> val instanceResponse = rdsClient.modifyDbInstance(request) println("The ARN of the modified database is ${instanceResponse.dbInstance?.dbInstanceArn}") } }
-
Untuk API detailnya, lihat M odifyDBInstance
in AWS SDKuntuk API referensi Kotlin.
-