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.
Contoh Amazon Keyspaces yang digunakan SDK untuk Kotlin
Contoh kode berikut menunjukkan cara melakukan tindakan dan menerapkan skenario umum dengan menggunakan AWS SDK for Kotlin dengan Amazon Keyspaces.
Dasar-dasar adalah contoh kode yang menunjukkan kepada Anda bagaimana melakukan operasi penting dalam suatu layanan.
Tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Sementara tindakan menunjukkan cara memanggil fungsi layanan individual, Anda dapat melihat tindakan dalam konteks dalam skenario terkait.
Setiap contoh menyertakan tautan ke kode sumber lengkap, di mana Anda dapat menemukan instruksi tentang cara mengatur dan menjalankan kode dalam konteks.
Memulai
Contoh kode berikut menunjukkan cara memulai menggunakan Amazon Keyspaces.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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 */ suspend fun main() { listKeyspaces() } suspend fun listKeyspaces() { val keyspacesRequest = ListKeyspacesRequest { maxResults = 10 } KeyspacesClient { region = "us-east-1" }.use { keyClient -> val response = keyClient.listKeyspaces(keyspacesRequest) response.keyspaces?.forEach { keyspace -> println("The name of the keyspace is ${keyspace.keyspaceName}") } } }
-
Untuk API detailnya, lihat ListKeyspaces AWS
SDKAPIreferensi Kotlin.
-
Hal-hal mendasar
Contoh kode berikut ini menunjukkan cara:
Buat keyspace dan tabel. Skema tabel menyimpan data film dan mengaktifkan point-in-time pemulihan.
Connect ke keyspace menggunakan TLS koneksi aman dengan otentikasi SiGv4.
Kueri tabel. Tambahkan, ambil, dan perbarui data film.
Perbarui tabel. Tambahkan kolom untuk melacak film yang ditonton.
Kembalikan tabel ke keadaan sebelumnya dan bersihkan sumber daya.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode 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 uses a secure file format to hold certificate information for Kotlin applications. This is required to make a connection to Amazon Keyspaces. For more information, see the following documentation topic: https://docs.aws.amazon.com/keyspaces/latest/devguide/using_java_driver.html This Kotlin example performs the following tasks: 1. Create a keyspace. 2. Check for keyspace existence. 3. List keyspaces using a paginator. 4. Create a table with a simple movie data schema and enable point-in-time recovery. 5. Check for the table to be in an Active state. 6. List all tables in the keyspace. 7. Use a Cassandra driver to insert some records into the Movie table. 8. Get all records from the Movie table. 9. Get a specific Movie. 10. Get a UTC timestamp for the current time. 11. Update the table schema to add a ‘watched’ Boolean column. 12. Update an item as watched. 13. Query for items with watched = True. 14. Restore the table back to the previous state using the timestamp. 15. Check for completion of the restore action. 16. Delete the table. 17. Confirm that both tables are deleted. 18. Delete the keyspace. */ /* Usage: fileName - The name of the JSON file that contains movie data. (Get this file from the GitHub repo at resources/sample_file.) keyspaceName - The name of the keyspace to create. */ val DASHES: String = String(CharArray(80)).replace("\u0000", "-") suspend fun main() { val fileName = "<Replace with the JSON file that contains movie data>" val keyspaceName = "<Replace with the name of the keyspace to create>" val titleUpdate = "The Family" val yearUpdate = 2013 val tableName = "MovieKotlin" val tableNameRestore = "MovieRestore" val loader = DriverConfigLoader.fromClasspath("application.conf") val session = CqlSession .builder() .withConfigLoader(loader) .build() println(DASHES) println("Welcome to the Amazon Keyspaces example scenario.") println(DASHES) println(DASHES) println("1. Create a keyspace.") createKeySpace(keyspaceName) println(DASHES) println(DASHES) delay(5000) println("2. Check for keyspace existence.") checkKeyspaceExistence(keyspaceName) println(DASHES) println(DASHES) println("3. List keyspaces using a paginator.") listKeyspacesPaginator() println(DASHES) println(DASHES) println("4. Create a table with a simple movie data schema and enable point-in-time recovery.") createTable(keyspaceName, tableName) println(DASHES) println(DASHES) println("5. Check for the table to be in an Active state.") delay(6000) checkTable(keyspaceName, tableName) println(DASHES) println(DASHES) println("6. List all tables in the keyspace.") listTables(keyspaceName) println(DASHES) println(DASHES) println("7. Use a Cassandra driver to insert some records into the Movie table.") delay(6000) loadData(session, fileName, keyspaceName) println(DASHES) println(DASHES) println("8. Get all records from the Movie table.") getMovieData(session, keyspaceName) println(DASHES) println(DASHES) println("9. Get a specific Movie.") getSpecificMovie(session, keyspaceName) println(DASHES) println(DASHES) println("10. Get a UTC timestamp for the current time.") val utc = ZonedDateTime.now(ZoneOffset.UTC) println("DATETIME = ${Date.from(utc.toInstant())}") println(DASHES) println(DASHES) println("11. Update the table schema to add a watched Boolean column.") updateTable(keyspaceName, tableName) println(DASHES) println(DASHES) println("12. Update an item as watched.") delay(10000) // Wait 10 seconds for the update. updateRecord(session, keyspaceName, titleUpdate, yearUpdate) println(DASHES) println(DASHES) println("13. Query for items with watched = True.") getWatchedData(session, keyspaceName) println(DASHES) println(DASHES) println("14. Restore the table back to the previous state using the timestamp.") println("Note that the restore operation can take up to 20 minutes.") restoreTable(keyspaceName, utc) println(DASHES) println(DASHES) println("15. Check for completion of the restore action.") delay(5000) checkRestoredTable(keyspaceName, "MovieRestore") println(DASHES) println(DASHES) println("16. Delete both tables.") deleteTable(keyspaceName, tableName) deleteTable(keyspaceName, tableNameRestore) println(DASHES) println(DASHES) println("17. Confirm that both tables are deleted.") checkTableDelete(keyspaceName, tableName) checkTableDelete(keyspaceName, tableNameRestore) println(DASHES) println(DASHES) println("18. Delete the keyspace.") deleteKeyspace(keyspaceName) println(DASHES) println(DASHES) println("The scenario has completed successfully.") println(DASHES) } suspend fun deleteKeyspace(keyspaceNameVal: String?) { val deleteKeyspaceRequest = DeleteKeyspaceRequest { keyspaceName = keyspaceNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> keyClient.deleteKeyspace(deleteKeyspaceRequest) } } suspend fun checkTableDelete( keyspaceNameVal: String?, tableNameVal: String?, ) { var status: String var response: GetTableResponse val tableRequest = GetTableRequest { keyspaceName = keyspaceNameVal tableName = tableNameVal } try { KeyspacesClient { region = "us-east-1" }.use { keyClient -> // Keep looping until the table cannot be found and a ResourceNotFoundException is thrown. while (true) { response = keyClient.getTable(tableRequest) status = response.status.toString() println(". The table status is $status") delay(500) } } } catch (e: ResourceNotFoundException) { println(e.message) } println("The table is deleted") } suspend fun deleteTable( keyspaceNameVal: String?, tableNameVal: String?, ) { val tableRequest = DeleteTableRequest { keyspaceName = keyspaceNameVal tableName = tableNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> keyClient.deleteTable(tableRequest) } } suspend fun checkRestoredTable( keyspaceNameVal: String?, tableNameVal: String?, ) { var tableStatus = false var status: String var response: GetTableResponse? = null val tableRequest = GetTableRequest { keyspaceName = keyspaceNameVal tableName = tableNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> while (!tableStatus) { response = keyClient.getTable(tableRequest) status = response!!.status.toString() println("The table status is $status") if (status.compareTo("ACTIVE") == 0) { tableStatus = true } delay(500) } val cols = response!!.schemaDefinition?.allColumns if (cols != null) { for (def in cols) { println("The column name is ${def.name}") println("The column type is ${def.type}") } } } } suspend fun restoreTable( keyspaceName: String?, utc: ZonedDateTime, ) { // Create an aws.smithy.kotlin.runtime.time.Instant value. val timeStamp = aws.smithy.kotlin.runtime.time .Instant(utc.toInstant()) val restoreTableRequest = RestoreTableRequest { restoreTimestamp = timeStamp sourceTableName = "MovieKotlin" targetKeyspaceName = keyspaceName targetTableName = "MovieRestore" sourceKeyspaceName = keyspaceName } KeyspacesClient { region = "us-east-1" }.use { keyClient -> val response = keyClient.restoreTable(restoreTableRequest) println("The ARN of the restored table is ${response.restoredTableArn}") } } fun getWatchedData( session: CqlSession, keyspaceName: String, ) { val resultSet = session.execute("SELECT * FROM \"$keyspaceName\".\"MovieKotlin\" WHERE watched = true ALLOW FILTERING;") resultSet.forEach { item: Row -> println("The Movie title is ${item.getString("title")}") println("The Movie year is ${item.getInt("year")}") println("The plot is ${item.getString("plot")}") } } fun updateRecord( session: CqlSession, keySpace: String, titleUpdate: String?, yearUpdate: Int, ) { val sqlStatement = "UPDATE \"$keySpace\".\"MovieKotlin\" SET watched=true WHERE title = :k0 AND year = :k1;" val builder = BatchStatement.builder(DefaultBatchType.UNLOGGED) builder.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM) val preparedStatement = session.prepare(sqlStatement) builder.addStatement( preparedStatement .boundStatementBuilder() .setString("k0", titleUpdate) .setInt("k1", yearUpdate) .build(), ) val batchStatement = builder.build() session.execute(batchStatement) } suspend fun updateTable( keySpace: String?, tableNameVal: String?, ) { val def = ColumnDefinition { name = "watched" type = "boolean" } val tableRequest = UpdateTableRequest { keyspaceName = keySpace tableName = tableNameVal addColumns = listOf(def) } KeyspacesClient { region = "us-east-1" }.use { keyClient -> keyClient.updateTable(tableRequest) } } fun getSpecificMovie( session: CqlSession, keyspaceName: String, ) { val resultSet = session.execute("SELECT * FROM \"$keyspaceName\".\"MovieKotlin\" WHERE title = 'The Family' ALLOW FILTERING ;") resultSet.forEach { item: Row -> println("The Movie title is ${item.getString("title")}") println("The Movie year is ${item.getInt("year")}") println("The plot is ${item.getString("plot")}") } } // Get records from the Movie table. fun getMovieData( session: CqlSession, keyspaceName: String, ) { val resultSet = session.execute("SELECT * FROM \"$keyspaceName\".\"MovieKotlin\";") resultSet.forEach { item: Row -> println("The Movie title is ${item.getString("title")}") println("The Movie year is ${item.getInt("year")}") println("The plot is ${item.getString("plot")}") } } // Load data into the table. fun loadData( session: CqlSession, fileName: String, keySpace: String, ) { val sqlStatement = "INSERT INTO \"$keySpace\".\"MovieKotlin\" (title, year, plot) values (:k0, :k1, :k2)" val parser = JsonFactory().createParser(File(fileName)) val rootNode = ObjectMapper().readTree<JsonNode>(parser) val iter: Iterator<JsonNode> = rootNode.iterator() var currentNode: ObjectNode var t = 0 while (iter.hasNext()) { if (t == 50) { break } currentNode = iter.next() as ObjectNode val year = currentNode.path("year").asInt() val title = currentNode.path("title").asText() val info = currentNode.path("info").toString() // Insert the data into the Amazon Keyspaces table. val builder = BatchStatement.builder(DefaultBatchType.UNLOGGED) builder.setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM) val preparedStatement: PreparedStatement = session.prepare(sqlStatement) builder.addStatement( preparedStatement .boundStatementBuilder() .setString("k0", title) .setInt("k1", year) .setString("k2", info) .build(), ) val batchStatement = builder.build() session.execute(batchStatement) t++ } } suspend fun listTables(keyspaceNameVal: String?) { val tablesRequest = ListTablesRequest { keyspaceName = keyspaceNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> keyClient .listTablesPaginated(tablesRequest) .transform { it.tables?.forEach { obj -> emit(obj) } } .collect { obj -> println(" ARN: ${obj.resourceArn} Table name: ${obj.tableName}") } } } suspend fun checkTable( keyspaceNameVal: String?, tableNameVal: String?, ) { var tableStatus = false var status: String var response: GetTableResponse? = null val tableRequest = GetTableRequest { keyspaceName = keyspaceNameVal tableName = tableNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> while (!tableStatus) { response = keyClient.getTable(tableRequest) status = response!!.status.toString() println(". The table status is $status") if (status.compareTo("ACTIVE") == 0) { tableStatus = true } delay(500) } val cols: List<ColumnDefinition>? = response!!.schemaDefinition?.allColumns if (cols != null) { for (def in cols) { println("The column name is ${def.name}") println("The column type is ${def.type}") } } } } suspend fun createTable( keySpaceVal: String?, tableNameVal: String?, ) { // Set the columns. val defTitle = ColumnDefinition { name = "title" type = "text" } val defYear = ColumnDefinition { name = "year" type = "int" } val defReleaseDate = ColumnDefinition { name = "release_date" type = "timestamp" } val defPlot = ColumnDefinition { name = "plot" type = "text" } val colList = ArrayList<ColumnDefinition>() colList.add(defTitle) colList.add(defYear) colList.add(defReleaseDate) colList.add(defPlot) // Set the keys. val yearKey = PartitionKey { name = "year" } val titleKey = PartitionKey { name = "title" } val keyList = ArrayList<PartitionKey>() keyList.add(yearKey) keyList.add(titleKey) val schemaDefinitionOb = SchemaDefinition { partitionKeys = keyList allColumns = colList } val timeRecovery = PointInTimeRecovery { status = PointInTimeRecoveryStatus.Enabled } val tableRequest = CreateTableRequest { keyspaceName = keySpaceVal tableName = tableNameVal schemaDefinition = schemaDefinitionOb pointInTimeRecovery = timeRecovery } KeyspacesClient { region = "us-east-1" }.use { keyClient -> val response = keyClient.createTable(tableRequest) println("The table ARN is ${response.resourceArn}") } } suspend fun listKeyspacesPaginator() { KeyspacesClient { region = "us-east-1" }.use { keyClient -> keyClient .listKeyspacesPaginated(ListKeyspacesRequest {}) .transform { it.keyspaces?.forEach { obj -> emit(obj) } } .collect { obj -> println("Name: ${obj.keyspaceName}") } } } suspend fun checkKeyspaceExistence(keyspaceNameVal: String?) { val keyspaceRequest = GetKeyspaceRequest { keyspaceName = keyspaceNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> val response: GetKeyspaceResponse = keyClient.getKeyspace(keyspaceRequest) val name = response.keyspaceName println("The $name KeySpace is ready") } } suspend fun createKeySpace(keyspaceNameVal: String) { val keyspaceRequest = CreateKeyspaceRequest { keyspaceName = keyspaceNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> val response = keyClient.createKeyspace(keyspaceRequest) println("The ARN of the KeySpace is ${response.resourceArn}") } }
-
Untuk API detailnya, lihat topik berikut AWS SDKuntuk API referensi Kotlin.
-
Tindakan
Contoh kode berikut menunjukkan cara menggunakanCreateKeyspace
.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun createKeySpace(keyspaceNameVal: String) { val keyspaceRequest = CreateKeyspaceRequest { keyspaceName = keyspaceNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> val response = keyClient.createKeyspace(keyspaceRequest) println("The ARN of the KeySpace is ${response.resourceArn}") } }
-
Untuk API detailnya, lihat CreateKeyspace AWS
SDKAPIreferensi Kotlin.
-
Contoh kode berikut menunjukkan cara menggunakanCreateTable
.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun createTable( keySpaceVal: String?, tableNameVal: String?, ) { // Set the columns. val defTitle = ColumnDefinition { name = "title" type = "text" } val defYear = ColumnDefinition { name = "year" type = "int" } val defReleaseDate = ColumnDefinition { name = "release_date" type = "timestamp" } val defPlot = ColumnDefinition { name = "plot" type = "text" } val colList = ArrayList<ColumnDefinition>() colList.add(defTitle) colList.add(defYear) colList.add(defReleaseDate) colList.add(defPlot) // Set the keys. val yearKey = PartitionKey { name = "year" } val titleKey = PartitionKey { name = "title" } val keyList = ArrayList<PartitionKey>() keyList.add(yearKey) keyList.add(titleKey) val schemaDefinitionOb = SchemaDefinition { partitionKeys = keyList allColumns = colList } val timeRecovery = PointInTimeRecovery { status = PointInTimeRecoveryStatus.Enabled } val tableRequest = CreateTableRequest { keyspaceName = keySpaceVal tableName = tableNameVal schemaDefinition = schemaDefinitionOb pointInTimeRecovery = timeRecovery } KeyspacesClient { region = "us-east-1" }.use { keyClient -> val response = keyClient.createTable(tableRequest) println("The table ARN is ${response.resourceArn}") } }
-
Untuk API detailnya, lihat CreateTable AWS
SDKAPIreferensi Kotlin.
-
Contoh kode berikut menunjukkan cara menggunakanDeleteKeyspace
.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun deleteKeyspace(keyspaceNameVal: String?) { val deleteKeyspaceRequest = DeleteKeyspaceRequest { keyspaceName = keyspaceNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> keyClient.deleteKeyspace(deleteKeyspaceRequest) } }
-
Untuk API detailnya, lihat DeleteKeyspace AWS
SDKAPIreferensi Kotlin.
-
Contoh kode berikut menunjukkan cara menggunakanDeleteTable
.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun deleteTable( keyspaceNameVal: String?, tableNameVal: String?, ) { val tableRequest = DeleteTableRequest { keyspaceName = keyspaceNameVal tableName = tableNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> keyClient.deleteTable(tableRequest) } }
-
Untuk API detailnya, lihat DeleteTable AWS
SDKAPIreferensi Kotlin.
-
Contoh kode berikut menunjukkan cara menggunakanGetKeyspace
.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun checkKeyspaceExistence(keyspaceNameVal: String?) { val keyspaceRequest = GetKeyspaceRequest { keyspaceName = keyspaceNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> val response: GetKeyspaceResponse = keyClient.getKeyspace(keyspaceRequest) val name = response.keyspaceName println("The $name KeySpace is ready") } }
-
Untuk API detailnya, lihat GetKeyspace AWS
SDKAPIreferensi Kotlin.
-
Contoh kode berikut menunjukkan cara menggunakanGetTable
.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun checkTable( keyspaceNameVal: String?, tableNameVal: String?, ) { var tableStatus = false var status: String var response: GetTableResponse? = null val tableRequest = GetTableRequest { keyspaceName = keyspaceNameVal tableName = tableNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> while (!tableStatus) { response = keyClient.getTable(tableRequest) status = response!!.status.toString() println(". The table status is $status") if (status.compareTo("ACTIVE") == 0) { tableStatus = true } delay(500) } val cols: List<ColumnDefinition>? = response!!.schemaDefinition?.allColumns if (cols != null) { for (def in cols) { println("The column name is ${def.name}") println("The column type is ${def.type}") } } } }
-
Untuk API detailnya, lihat GetTable AWS
SDKAPIreferensi Kotlin.
-
Contoh kode berikut menunjukkan cara menggunakanListKeyspaces
.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun listKeyspacesPaginator() { KeyspacesClient { region = "us-east-1" }.use { keyClient -> keyClient .listKeyspacesPaginated(ListKeyspacesRequest {}) .transform { it.keyspaces?.forEach { obj -> emit(obj) } } .collect { obj -> println("Name: ${obj.keyspaceName}") } } }
-
Untuk API detailnya, lihat ListKeyspaces AWS
SDKAPIreferensi Kotlin.
-
Contoh kode berikut menunjukkan cara menggunakanListTables
.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun listTables(keyspaceNameVal: String?) { val tablesRequest = ListTablesRequest { keyspaceName = keyspaceNameVal } KeyspacesClient { region = "us-east-1" }.use { keyClient -> keyClient .listTablesPaginated(tablesRequest) .transform { it.tables?.forEach { obj -> emit(obj) } } .collect { obj -> println(" ARN: ${obj.resourceArn} Table name: ${obj.tableName}") } } }
-
Untuk API detailnya, lihat ListTables AWS
SDKAPIreferensi Kotlin.
-
Contoh kode berikut menunjukkan cara menggunakanRestoreTable
.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun restoreTable( keyspaceName: String?, utc: ZonedDateTime, ) { // Create an aws.smithy.kotlin.runtime.time.Instant value. val timeStamp = aws.smithy.kotlin.runtime.time .Instant(utc.toInstant()) val restoreTableRequest = RestoreTableRequest { restoreTimestamp = timeStamp sourceTableName = "MovieKotlin" targetKeyspaceName = keyspaceName targetTableName = "MovieRestore" sourceKeyspaceName = keyspaceName } KeyspacesClient { region = "us-east-1" }.use { keyClient -> val response = keyClient.restoreTable(restoreTableRequest) println("The ARN of the restored table is ${response.restoredTableArn}") } }
-
Untuk API detailnya, lihat RestoreTable AWS
SDKAPIreferensi Kotlin.
-
Contoh kode berikut menunjukkan cara menggunakanUpdateTable
.
- SDKuntuk Kotlin
-
catatan
Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara pengaturan dan menjalankannya di Repositori Contoh Kode AWS
. suspend fun updateTable( keySpace: String?, tableNameVal: String?, ) { val def = ColumnDefinition { name = "watched" type = "boolean" } val tableRequest = UpdateTableRequest { keyspaceName = keySpace tableName = tableNameVal addColumns = listOf(def) } KeyspacesClient { region = "us-east-1" }.use { keyClient -> keyClient.updateTable(tableRequest) } }
-
Untuk API detailnya, lihat UpdateTable AWS
SDKAPIreferensi Kotlin.
-