AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
用SDK于 Kotlin 的 Aurora 示例
以下代码示例向您展示了如何使用 for Kotlin 和 Aurora 来执行操作和实现常见场景。 AWS SDK
基础知识是向您展示如何在服务中执行基本操作的代码示例。
操作是大型程序的代码摘录,必须在上下文中运行。您可以通过操作了解如何调用单个服务函数,还可以通过函数相关场景的上下文查看操作。
场景是向您展示如何通过在一个服务中调用多个函数或与其他 AWS 服务结合来完成特定任务的代码示例。
每个示例都包含一个指向完整源代码的链接,您可以在其中找到有关如何在上下文中设置和运行代码的说明。
基础知识
以下代码示例展示了如何:
创建自定义 Aurora 数据库集群参数组并设置参数值。
创建一个使用参数组的数据库集群。
创建包含数据库的数据库实例。
拍摄数据库集群的快照,然后清理资源。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 /** 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}") } } }
-
有关API详细信息,请参阅中的以下主题以获取 Kotlin AWS SDK API 参考。
-
操作
以下代码示例显示了如何使用CreateDBCluster
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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详细信息,请参阅 C reateDBCluster
中的 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用CreateDBClusterParameterGroup
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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详细信息,请参阅 C reateDBCluster ParameterGroup
中的 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用CreateDBClusterSnapshot
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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}") } }
-
有关API详细信息,请参阅中的 C reateDBCluster 快照
以获取 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用CreateDBInstance
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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详细信息,请参阅 C reateDBInstance
中的 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用DeleteDBCluster
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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详细信息,请参见eleteDBCluster中的 D
以获取 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用DeleteDBClusterParameterGroup
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 @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.") } }
-
有关API详细信息,请参见eleteDBClusterParameterGroup中的 D
以获取 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用DeleteDBInstance
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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}") } }
-
有关API详细信息,请参见eleteDBInstance中的 D
以获取 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用DescribeDBClusterParameterGroups
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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}") } } }
-
有关API详细信息,请参见escribeDBClusterParameterGroups中的 D
以获取 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用DescribeDBClusterParameters
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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}") } } } } }
-
有关API详细信息,请参阅中的 D escribeDBCluster 参数
以获取 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用DescribeDBClusterSnapshots
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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!") }
-
有关API详细信息,请参阅中的 D escribeDBCluster 快照
以获取 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用DescribeDBClusters
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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}") } } } } }
-
有关API详细信息,请参见escribeDBClusters中的 D
以获取 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用DescribeDBEngineVersions
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 // 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}") } } }
-
有关API详细信息,请参阅中的 D escribeDBEngine 版本
以获取 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用DescribeDBInstances
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 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") }
-
有关API详细信息,请参见escribeDBInstances中的 D
以获取 Kotlin AWS SDK API 参考。
-
以下代码示例显示了如何使用ModifyDBClusterParameterGroup
。
- SDK对于 Kotlin 来说
-
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 // 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") } }
-
有关API详细信息,请参阅 M odifyDBCluster ParameterGroup
中的 Kotlin AWS SDK API 参考。
-
场景
以下代码示例说明如何创建一个 Web 应用程序,该应用程序可跟踪 Amazon Aurora Serverless 数据库中的工作项目,并使用亚马逊简单电子邮件服务 (AmazonSES) 发送报告。
- SDK对于 Kotlin 来说
-
演示如何创建用于跟踪和报告存储在 Amazon RDS 数据库中的工作项的 Web 应用程序。
有关如何设置查询 Amazon Aurora Serverless 数据RESTAPI的 Spring 以及供 React 应用程序使用的完整源代码和说明,请参阅上的GitHub
完整示例。 本示例中使用的服务
Aurora
Amazon RDS
亚马逊RDS数据服务
Amazon SES