Aurora-Beispiele mit SDK für Kotlin - AWS SDK-Codebeispiele

Weitere AWS SDK-Beispiele sind im Repo AWS Doc SDK Examples GitHub verfügbar.

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Aurora-Beispiele mit SDK für Kotlin

Die folgenden Codebeispiele zeigen Ihnen, wie Sie mithilfe des AWS SDK für Kotlin mit Aurora Aktionen ausführen und allgemeine Szenarien implementieren.

Bei Grundlagen handelt es sich um Code-Beispiele, die Ihnen zeigen, wie Sie die wesentlichen Vorgänge innerhalb eines Services ausführen.

Aktionen sind Codeauszüge aus größeren Programmen und müssen im Kontext ausgeführt werden. Während Aktionen Ihnen zeigen, wie Sie einzelne Service-Funktionen aufrufen, können Sie Aktionen im Kontext der zugehörigen Szenarios anzeigen.

Szenarien sind Code-Beispiele, die Ihnen zeigen, wie Sie bestimmte Aufgaben ausführen, indem Sie mehrere Funktionen innerhalb eines Services aufrufen oder mit anderen AWS-Services kombinieren.

Jedes Beispiel enthält einen Link zum vollständigen Quellcode, in dem Sie Anweisungen zum Einrichten und Ausführen des Codes im Kontext finden.

Grundlagen

Wie das aussehen kann, sehen Sie am nachfolgenden Beispielcode:

  • Erstellen Sie eine benutzerdefinierte Aurora-DB-Cluster-Parametergruppe und legen Sie Parameterwerte fest.

  • Erstellen Sie einen DB-Cluster, der die Parametergruppe verwendet.

  • Erstellen Sie eine DB-Instance, die eine Datenbank enthält.

  • Erstellen Sie einen Snapshot des DB-Clusters und bereinigen Sie dann die Ressourcen.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

/** Before running this Kotlin 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-kotlin/latest/developer-guide/setup.html This example requires an AWS Secrets Manager secret that contains the database credentials. If you do not create a secret, this example will not work. For more details, see: https://docs.aws.amazon.com/secretsmanager/latest/userguide/integrating_how-services-use-secrets_RS.html This Kotlin example performs the following tasks: 1. Returns a list of the available DB engines. 2. Creates a custom DB parameter group. 3. Gets the parameter groups. 4. Gets the parameters in the group. 5. Modifies the auto_increment_increment parameter. 6. Displays the updated parameter value. 7. Gets a list of allowed engine versions. 8. Creates an Aurora DB cluster database. 9. Waits for DB instance to be ready. 10. Gets a list of instance classes available for the selected engine. 11. Creates a database instance in the cluster. 12. Waits for the database instance in the cluster to be ready. 13. Creates a snapshot. 14. Waits for DB snapshot to be ready. 15. Deletes the DB instance. 16. Deletes the DB cluster. 17. Deletes the DB cluster group. */ var slTime: Long = 20 suspend fun main(args: Array<String>) { val usage = """ Usage: <dbClusterGroupName> <dbParameterGroupFamily> <dbInstanceClusterIdentifier> <dbName> <dbSnapshotIdentifier> <secretName> Where: dbClusterGroupName - The database group name. dbParameterGroupFamily - The database parameter group name. dbInstanceClusterIdentifier - The database instance identifier. dbName - The database name. dbSnapshotIdentifier - The snapshot identifier. secretName - The name of the AWS Secrets Manager secret that contains the database credentials. """ if (args.size != 7) { println(usage) exitProcess(1) } val dbClusterGroupName = args[0] val dbParameterGroupFamily = args[1] val dbInstanceClusterIdentifier = args[2] val dbInstanceIdentifier = args[3] val dbName = args[4] val dbSnapshotIdentifier = args[5] val secretName = args[6] val gson = Gson() val user = gson.fromJson(getSecretValues(secretName).toString(), User::class.java) val username = user.username val userPassword = user.password println("1. Return a list of the available DB engines") describeAuroraDBEngines() println("2. Create a custom parameter group") createDBClusterParameterGroup(dbClusterGroupName, dbParameterGroupFamily) println("3. Get the parameter group") describeDbClusterParameterGroups(dbClusterGroupName) println("4. Get the parameters in the group") describeDbClusterParameters(dbClusterGroupName, 0) println("5. Modify the auto_increment_offset parameter") modifyDBClusterParas(dbClusterGroupName) println("6. Display the updated parameter value") describeDbClusterParameters(dbClusterGroupName, -1) println("7. Get a list of allowed engine versions") getAllowedClusterEngines(dbParameterGroupFamily) println("8. Create an Aurora DB cluster database") val arnClusterVal = createDBCluster(dbClusterGroupName, dbName, dbInstanceClusterIdentifier, username, userPassword) println("The ARN of the cluster is $arnClusterVal") println("9. Wait for DB instance to be ready") waitForClusterInstanceReady(dbInstanceClusterIdentifier) println("10. Get a list of instance classes available for the selected engine") val instanceClass = getListInstanceClasses() println("11. Create a database instance in the cluster.") val clusterDBARN = createDBInstanceCluster(dbInstanceIdentifier, dbInstanceClusterIdentifier, instanceClass) println("The ARN of the database is $clusterDBARN") println("12. Wait for DB instance to be ready") waitDBAuroraInstanceReady(dbInstanceIdentifier) println("13. Create a snapshot") createDBClusterSnapshot(dbInstanceClusterIdentifier, dbSnapshotIdentifier) println("14. Wait for DB snapshot to be ready") waitSnapshotReady(dbSnapshotIdentifier, dbInstanceClusterIdentifier) println("15. Delete the DB instance") deleteDBInstance(dbInstanceIdentifier) println("16. Delete the DB cluster") deleteCluster(dbInstanceClusterIdentifier) println("17. Delete the DB cluster group") if (clusterDBARN != null) { deleteDBClusterGroup(dbClusterGroupName, clusterDBARN) } println("The Scenario has successfully completed.") } @Throws(InterruptedException::class) suspend fun deleteDBClusterGroup( dbClusterGroupName: String, clusterDBARN: String, ) { var isDataDel = false var didFind: Boolean var instanceARN: String RdsClient { region = "us-west-2" }.use { rdsClient -> // Make sure that the database has been deleted. while (!isDataDel) { val response = rdsClient.describeDbInstances() val instanceList = response.dbInstances val listSize = instanceList?.size isDataDel = false didFind = false var index = 1 if (instanceList != null) { for (instance in instanceList) { instanceARN = instance.dbInstanceArn.toString() if (instanceARN.compareTo(clusterDBARN) == 0) { println("$clusterDBARN still exists") didFind = true } if (index == listSize && !didFind) { // Went through the entire list and did not find the database ARN. isDataDel = true } delay(slTime * 1000) index++ } } } val clusterParameterGroupRequest = DeleteDbClusterParameterGroupRequest { dbClusterParameterGroupName = dbClusterGroupName } rdsClient.deleteDbClusterParameterGroup(clusterParameterGroupRequest) println("$dbClusterGroupName was deleted.") } } suspend fun deleteCluster(dbInstanceClusterIdentifier: String) { val deleteDbClusterRequest = DeleteDbClusterRequest { dbClusterIdentifier = dbInstanceClusterIdentifier skipFinalSnapshot = true } RdsClient { region = "us-west-2" }.use { rdsClient -> rdsClient.deleteDbCluster(deleteDbClusterRequest) println("$dbInstanceClusterIdentifier was deleted!") } } suspend fun deleteDBInstance(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}") } } suspend fun waitSnapshotReady( dbSnapshotIdentifier: String?, dbInstanceClusterIdentifier: String?, ) { var snapshotReady = false var snapshotReadyStr: String println("Waiting for the snapshot to become available.") val snapshotsRequest = DescribeDbClusterSnapshotsRequest { dbClusterSnapshotIdentifier = dbSnapshotIdentifier dbClusterIdentifier = dbInstanceClusterIdentifier } RdsClient { region = "us-west-2" }.use { rdsClient -> while (!snapshotReady) { val response = rdsClient.describeDbClusterSnapshots(snapshotsRequest) val snapshotList = response.dbClusterSnapshots if (snapshotList != null) { for (snapshot in snapshotList) { snapshotReadyStr = snapshot.status.toString() if (snapshotReadyStr.contains("available")) { snapshotReady = true } else { println(".") delay(slTime * 5000) } } } } } println("The Snapshot is available!") } suspend fun createDBClusterSnapshot( dbInstanceClusterIdentifier: String?, dbSnapshotIdentifier: String?, ) { val snapshotRequest = CreateDbClusterSnapshotRequest { dbClusterIdentifier = dbInstanceClusterIdentifier dbClusterSnapshotIdentifier = dbSnapshotIdentifier } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.createDbClusterSnapshot(snapshotRequest) println("The Snapshot ARN is ${response.dbClusterSnapshot?.dbClusterSnapshotArn}") } } suspend fun waitDBAuroraInstanceReady(dbInstanceIdentifierVal: String?) { var instanceReady = false var instanceReadyStr: String println("Waiting for instance to become available.") val instanceRequest = DescribeDbInstancesRequest { dbInstanceIdentifier = dbInstanceIdentifierVal } var endpoint = "" RdsClient { region = "us-west-2" }.use { rdsClient -> while (!instanceReady) { val response = rdsClient.describeDbInstances(instanceRequest) response.dbInstances?.forEach { instance -> instanceReadyStr = instance.dbInstanceStatus.toString() if (instanceReadyStr.contains("available")) { endpoint = instance.endpoint?.address.toString() instanceReady = true } else { print(".") delay(sleepTime * 1000) } } } } println("Database instance is available! The connection endpoint is $endpoint") } suspend fun createDBInstanceCluster( dbInstanceIdentifierVal: String?, dbInstanceClusterIdentifierVal: String?, instanceClassVal: String?, ): String? { val instanceRequest = CreateDbInstanceRequest { dbInstanceIdentifier = dbInstanceIdentifierVal dbClusterIdentifier = dbInstanceClusterIdentifierVal engine = "aurora-mysql" dbInstanceClass = instanceClassVal } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.createDbInstance(instanceRequest) print("The status is ${response.dbInstance?.dbInstanceStatus}") return response.dbInstance?.dbInstanceArn } } suspend fun getListInstanceClasses(): String { val optionsRequest = DescribeOrderableDbInstanceOptionsRequest { engine = "aurora-mysql" maxRecords = 20 } var instanceClass = "" RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeOrderableDbInstanceOptions(optionsRequest) response.orderableDbInstanceOptions?.forEach { instanceOption -> instanceClass = instanceOption.dbInstanceClass.toString() println("The instance class is ${instanceOption.dbInstanceClass}") println("The engine version is ${instanceOption.engineVersion}") } } return instanceClass } // Waits until the database instance is available. suspend fun waitForClusterInstanceReady(dbClusterIdentifierVal: String?) { var instanceReady = false var instanceReadyStr: String println("Waiting for instance to become available.") val instanceRequest = DescribeDbClustersRequest { dbClusterIdentifier = dbClusterIdentifierVal } RdsClient { region = "us-west-2" }.use { rdsClient -> while (!instanceReady) { val response = rdsClient.describeDbClusters(instanceRequest) response.dbClusters?.forEach { cluster -> instanceReadyStr = cluster.status.toString() if (instanceReadyStr.contains("available")) { instanceReady = true } else { print(".") delay(sleepTime * 1000) } } } } println("Database cluster is available!") } suspend fun createDBCluster( dbParameterGroupFamilyVal: String?, dbName: String?, dbClusterIdentifierVal: String?, userName: String?, password: String?, ): String? { val clusterRequest = CreateDbClusterRequest { databaseName = dbName dbClusterIdentifier = dbClusterIdentifierVal dbClusterParameterGroupName = dbParameterGroupFamilyVal engine = "aurora-mysql" masterUsername = userName masterUserPassword = password } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.createDbCluster(clusterRequest) return response.dbCluster?.dbClusterArn } } // Get a list of allowed engine versions. suspend fun getAllowedClusterEngines(dbParameterGroupFamilyVal: String?) { val versionsRequest = DescribeDbEngineVersionsRequest { dbParameterGroupFamily = dbParameterGroupFamilyVal engine = "aurora-mysql" } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeDbEngineVersions(versionsRequest) response.dbEngineVersions?.forEach { dbEngine -> println("The engine version is ${dbEngine.engineVersion}") println("The engine description is ${dbEngine.dbEngineDescription}") } } } // Modify the auto_increment_offset parameter. suspend fun modifyDBClusterParas(dClusterGroupName: String?) { val parameter1 = Parameter { parameterName = "auto_increment_offset" applyMethod = ApplyMethod.fromValue("immediate") parameterValue = "5" } val paraList = ArrayList<Parameter>() paraList.add(parameter1) val groupRequest = ModifyDbClusterParameterGroupRequest { dbClusterParameterGroupName = dClusterGroupName parameters = paraList } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.modifyDbClusterParameterGroup(groupRequest) println("The parameter group ${response.dbClusterParameterGroupName} was successfully modified") } } suspend fun describeDbClusterParameters( dbCLusterGroupName: String?, flag: Int, ) { val dbParameterGroupsRequest: DescribeDbClusterParametersRequest dbParameterGroupsRequest = if (flag == 0) { DescribeDbClusterParametersRequest { dbClusterParameterGroupName = dbCLusterGroupName } } else { DescribeDbClusterParametersRequest { dbClusterParameterGroupName = dbCLusterGroupName source = "user" } } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeDbClusterParameters(dbParameterGroupsRequest) response.parameters?.forEach { para -> // Only print out information about either auto_increment_offset or auto_increment_increment. val paraName = para.parameterName if (paraName != null) { if (paraName.compareTo("auto_increment_offset") == 0 || paraName.compareTo("auto_increment_increment ") == 0) { println("*** The parameter name is $paraName") println("*** The parameter value is ${para.parameterValue}") println("*** The parameter data type is ${para.dataType}") println("*** The parameter description is ${para.description}") println("*** The parameter allowed values is ${para.allowedValues}") } } } } } suspend fun describeDbClusterParameterGroups(dbClusterGroupName: String?) { val groupsRequest = DescribeDbClusterParameterGroupsRequest { dbClusterParameterGroupName = dbClusterGroupName maxRecords = 20 } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeDbClusterParameterGroups(groupsRequest) response.dbClusterParameterGroups?.forEach { group -> println("The group name is ${group.dbClusterParameterGroupName}") println("The group ARN is ${group.dbClusterParameterGroupArn}") } } } suspend fun createDBClusterParameterGroup( dbClusterGroupNameVal: String?, dbParameterGroupFamilyVal: String?, ) { val groupRequest = CreateDbClusterParameterGroupRequest { dbClusterParameterGroupName = dbClusterGroupNameVal dbParameterGroupFamily = dbParameterGroupFamilyVal description = "Created by using the AWS SDK for Kotlin" } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.createDbClusterParameterGroup(groupRequest) println("The group name is ${response.dbClusterParameterGroup?.dbClusterParameterGroupName}") } } suspend fun describeAuroraDBEngines() { val engineVersionsRequest = DescribeDbEngineVersionsRequest { engine = "aurora-mysql" defaultOnly = true maxRecords = 20 } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeDbEngineVersions(engineVersionsRequest) response.dbEngineVersions?.forEach { engineOb -> println("The name of the DB parameter group family for the database engine is ${engineOb.dbParameterGroupFamily}") println("The name of the database engine ${engineOb.engine}") println("The version number of the database engine ${engineOb.engineVersion}") } } }

Aktionen

Das folgende Codebeispiel zeigt die VerwendungCreateDBCluster.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun createDBCluster( dbParameterGroupFamilyVal: String?, dbName: String?, dbClusterIdentifierVal: String?, userName: String?, password: String?, ): String? { val clusterRequest = CreateDbClusterRequest { databaseName = dbName dbClusterIdentifier = dbClusterIdentifierVal dbClusterParameterGroupName = dbParameterGroupFamilyVal engine = "aurora-mysql" masterUsername = userName masterUserPassword = password } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.createDbCluster(clusterRequest) return response.dbCluster?.dbClusterArn } }
  • API-Details finden Sie unter API-Referenz DBCluster im AWS SDK für Kotlin erstellen.

Das folgende Codebeispiel zeigt die VerwendungCreateDBClusterParameterGroup.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun createDBClusterParameterGroup( dbClusterGroupNameVal: String?, dbParameterGroupFamilyVal: String?, ) { val groupRequest = CreateDbClusterParameterGroupRequest { dbClusterParameterGroupName = dbClusterGroupNameVal dbParameterGroupFamily = dbParameterGroupFamilyVal description = "Created by using the AWS SDK for Kotlin" } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.createDbClusterParameterGroup(groupRequest) println("The group name is ${response.dbClusterParameterGroup?.dbClusterParameterGroupName}") } }
  • API-Details finden Sie unter API-Referenz DBCluster ParameterGroup im AWS SDK für Kotlin erstellen.

Das folgende Codebeispiel zeigt die VerwendungCreateDBClusterSnapshot.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun createDBClusterSnapshot( dbInstanceClusterIdentifier: String?, dbSnapshotIdentifier: String?, ) { val snapshotRequest = CreateDbClusterSnapshotRequest { dbClusterIdentifier = dbInstanceClusterIdentifier dbClusterSnapshotIdentifier = dbSnapshotIdentifier } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.createDbClusterSnapshot(snapshotRequest) println("The Snapshot ARN is ${response.dbClusterSnapshot?.dbClusterSnapshotArn}") } }

Das folgende Codebeispiel zeigt die VerwendungCreateDBInstance.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun createDBInstanceCluster( dbInstanceIdentifierVal: String?, dbInstanceClusterIdentifierVal: String?, instanceClassVal: String?, ): String? { val instanceRequest = CreateDbInstanceRequest { dbInstanceIdentifier = dbInstanceIdentifierVal dbClusterIdentifier = dbInstanceClusterIdentifierVal engine = "aurora-mysql" dbInstanceClass = instanceClassVal } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.createDbInstance(instanceRequest) print("The status is ${response.dbInstance?.dbInstanceStatus}") return response.dbInstance?.dbInstanceArn } }
  • API-Details finden Sie unter API-Referenz DBInstance im AWS SDK für Kotlin erstellen.

Das folgende Codebeispiel zeigt die VerwendungDeleteDBCluster.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun deleteCluster(dbInstanceClusterIdentifier: String) { val deleteDbClusterRequest = DeleteDbClusterRequest { dbClusterIdentifier = dbInstanceClusterIdentifier skipFinalSnapshot = true } RdsClient { region = "us-west-2" }.use { rdsClient -> rdsClient.deleteDbCluster(deleteDbClusterRequest) println("$dbInstanceClusterIdentifier was deleted!") } }
  • API-Details finden Sie unter Löschen DBCluster im AWS SDK für die Kotlin-API-Referenz.

Das folgende Codebeispiel zeigt die VerwendungDeleteDBClusterParameterGroup.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

@Throws(InterruptedException::class) suspend fun deleteDBClusterGroup( dbClusterGroupName: String, clusterDBARN: String, ) { var isDataDel = false var didFind: Boolean var instanceARN: String RdsClient { region = "us-west-2" }.use { rdsClient -> // Make sure that the database has been deleted. while (!isDataDel) { val response = rdsClient.describeDbInstances() val instanceList = response.dbInstances val listSize = instanceList?.size isDataDel = false didFind = false var index = 1 if (instanceList != null) { for (instance in instanceList) { instanceARN = instance.dbInstanceArn.toString() if (instanceARN.compareTo(clusterDBARN) == 0) { println("$clusterDBARN still exists") didFind = true } if (index == listSize && !didFind) { // Went through the entire list and did not find the database ARN. isDataDel = true } delay(slTime * 1000) index++ } } } val clusterParameterGroupRequest = DeleteDbClusterParameterGroupRequest { dbClusterParameterGroupName = dbClusterGroupName } rdsClient.deleteDbClusterParameterGroup(clusterParameterGroupRequest) println("$dbClusterGroupName was deleted.") } }

Das folgende Codebeispiel zeigt die VerwendungDeleteDBInstance.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun deleteDBInstance(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}") } }

Das folgende Codebeispiel zeigt die VerwendungDescribeDBClusterParameterGroups.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun describeDbClusterParameterGroups(dbClusterGroupName: String?) { val groupsRequest = DescribeDbClusterParameterGroupsRequest { dbClusterParameterGroupName = dbClusterGroupName maxRecords = 20 } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeDbClusterParameterGroups(groupsRequest) response.dbClusterParameterGroups?.forEach { group -> println("The group name is ${group.dbClusterParameterGroupName}") println("The group ARN is ${group.dbClusterParameterGroupArn}") } } }

Das folgende Codebeispiel zeigt die VerwendungDescribeDBClusterParameters.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun describeDbClusterParameters( dbCLusterGroupName: String?, flag: Int, ) { val dbParameterGroupsRequest: DescribeDbClusterParametersRequest dbParameterGroupsRequest = if (flag == 0) { DescribeDbClusterParametersRequest { dbClusterParameterGroupName = dbCLusterGroupName } } else { DescribeDbClusterParametersRequest { dbClusterParameterGroupName = dbCLusterGroupName source = "user" } } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeDbClusterParameters(dbParameterGroupsRequest) response.parameters?.forEach { para -> // Only print out information about either auto_increment_offset or auto_increment_increment. val paraName = para.parameterName if (paraName != null) { if (paraName.compareTo("auto_increment_offset") == 0 || paraName.compareTo("auto_increment_increment ") == 0) { println("*** The parameter name is $paraName") println("*** The parameter value is ${para.parameterValue}") println("*** The parameter data type is ${para.dataType}") println("*** The parameter description is ${para.description}") println("*** The parameter allowed values is ${para.allowedValues}") } } } } }

Das folgende Codebeispiel zeigt die VerwendungDescribeDBClusterSnapshots.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun waitSnapshotReady( dbSnapshotIdentifier: String?, dbInstanceClusterIdentifier: String?, ) { var snapshotReady = false var snapshotReadyStr: String println("Waiting for the snapshot to become available.") val snapshotsRequest = DescribeDbClusterSnapshotsRequest { dbClusterSnapshotIdentifier = dbSnapshotIdentifier dbClusterIdentifier = dbInstanceClusterIdentifier } RdsClient { region = "us-west-2" }.use { rdsClient -> while (!snapshotReady) { val response = rdsClient.describeDbClusterSnapshots(snapshotsRequest) val snapshotList = response.dbClusterSnapshots if (snapshotList != null) { for (snapshot in snapshotList) { snapshotReadyStr = snapshot.status.toString() if (snapshotReadyStr.contains("available")) { snapshotReady = true } else { println(".") delay(slTime * 5000) } } } } } println("The Snapshot is available!") }

Das folgende Codebeispiel zeigt die Verwendung. DescribeDBClusters

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun describeDbClusterParameters( dbCLusterGroupName: String?, flag: Int, ) { val dbParameterGroupsRequest: DescribeDbClusterParametersRequest dbParameterGroupsRequest = if (flag == 0) { DescribeDbClusterParametersRequest { dbClusterParameterGroupName = dbCLusterGroupName } } else { DescribeDbClusterParametersRequest { dbClusterParameterGroupName = dbCLusterGroupName source = "user" } } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeDbClusterParameters(dbParameterGroupsRequest) response.parameters?.forEach { para -> // Only print out information about either auto_increment_offset or auto_increment_increment. val paraName = para.parameterName if (paraName != null) { if (paraName.compareTo("auto_increment_offset") == 0 || paraName.compareTo("auto_increment_increment ") == 0) { println("*** The parameter name is $paraName") println("*** The parameter value is ${para.parameterValue}") println("*** The parameter data type is ${para.dataType}") println("*** The parameter description is ${para.description}") println("*** The parameter allowed values is ${para.allowedValues}") } } } } }
  • Einzelheiten zur API finden Sie unter DBClustersDescribe in AWS SDK for Kotlin API-Referenz.

Das folgende Codebeispiel zeigt die VerwendungDescribeDBEngineVersions.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

// Get a list of allowed engine versions. suspend fun getAllowedClusterEngines(dbParameterGroupFamilyVal: String?) { val versionsRequest = DescribeDbEngineVersionsRequest { dbParameterGroupFamily = dbParameterGroupFamilyVal engine = "aurora-mysql" } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeDbEngineVersions(versionsRequest) response.dbEngineVersions?.forEach { dbEngine -> println("The engine version is ${dbEngine.engineVersion}") println("The engine description is ${dbEngine.dbEngineDescription}") } } }

Das folgende Codebeispiel zeigt die VerwendungDescribeDBInstances.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

suspend fun waitDBAuroraInstanceReady(dbInstanceIdentifierVal: String?) { var instanceReady = false var instanceReadyStr: String println("Waiting for instance to become available.") val instanceRequest = DescribeDbInstancesRequest { dbInstanceIdentifier = dbInstanceIdentifierVal } var endpoint = "" RdsClient { region = "us-west-2" }.use { rdsClient -> while (!instanceReady) { val response = rdsClient.describeDbInstances(instanceRequest) response.dbInstances?.forEach { instance -> instanceReadyStr = instance.dbInstanceStatus.toString() if (instanceReadyStr.contains("available")) { endpoint = instance.endpoint?.address.toString() instanceReady = true } else { print(".") delay(sleepTime * 1000) } } } } println("Database instance is available! The connection endpoint is $endpoint") }
  • Einzelheiten zur API finden Sie unter DBInstancesDescribe in AWS SDK for Kotlin API-Referenz.

Das folgende Codebeispiel zeigt die VerwendungModifyDBClusterParameterGroup.

SDK für Kotlin
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

// Modify the auto_increment_offset parameter. suspend fun modifyDBClusterParas(dClusterGroupName: String?) { val parameter1 = Parameter { parameterName = "auto_increment_offset" applyMethod = ApplyMethod.fromValue("immediate") parameterValue = "5" } val paraList = ArrayList<Parameter>() paraList.add(parameter1) val groupRequest = ModifyDbClusterParameterGroupRequest { dbClusterParameterGroupName = dClusterGroupName parameters = paraList } RdsClient { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.modifyDbClusterParameterGroup(groupRequest) println("The parameter group ${response.dbClusterParameterGroupName} was successfully modified") } }

Szenarien

Das folgende Codebeispiel zeigt, wie Sie eine Webanwendung erstellen, die Arbeitsaufgaben in einer serverlosen Amazon Aurora Aurora-Datenbank verfolgt und Amazon Simple Email Service (Amazon SES) zum Senden von Berichten verwendet.

SDK für Kotlin

Zeigt, wie eine Webanwendung erstellt wird, die Arbeitselemente, die in einer Amazon RDS-Datenbank gespeichert sind, verfolgt und darüber berichtet.

Den vollständigen Quellcode und Anweisungen zur Einrichtung einer Spring REST-API, die Amazon Aurora Aurora-Serverless-Daten abfragt und von einer React-Anwendung verwendet werden kann, finden Sie im vollständigen Beispiel unter GitHub.

In diesem Beispiel verwendete Dienste
  • Aurora

  • Amazon RDS

  • Amazon RDS Data Service

  • Amazon SES