Skip to content

Commit

Permalink
added more lintered files
Browse files Browse the repository at this point in the history
  • Loading branch information
scmacdon committed Jun 8, 2024
1 parent 273ebb3 commit 6056394
Show file tree
Hide file tree
Showing 17 changed files with 1,749 additions and 1,625 deletions.
4 changes: 2 additions & 2 deletions kotlin/services/dynamodb/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ repositories {
}
apply(plugin = "org.jlleitschuh.gradle.ktlint")
dependencies {
implementation("aws.sdk.kotlin:dynamodb:1.0.30")
implementation("aws.sdk.kotlin:secretsmanager:1.0.30")
implementation("aws.sdk.kotlin:dynamodb:1.2.28")
implementation("aws.sdk.kotlin:secretsmanager:1.2.28")
implementation("aws.smithy.kotlin:http-client-engine-okhttp:0.30.0")
implementation("aws.smithy.kotlin:http-client-engine-crt:0.30.0")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,84 +1,91 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.dynamodb

// snippet-start:[dynamodb.kotlin.create_table.import]
import aws.sdk.kotlin.services.dynamodb.DynamoDbClient
import aws.sdk.kotlin.services.dynamodb.model.AttributeDefinition
import aws.sdk.kotlin.services.dynamodb.model.CreateTableRequest
import aws.sdk.kotlin.services.dynamodb.model.KeySchemaElement
import aws.sdk.kotlin.services.dynamodb.model.KeyType
import aws.sdk.kotlin.services.dynamodb.model.ProvisionedThroughput
import aws.sdk.kotlin.services.dynamodb.model.ScalarAttributeType
import aws.sdk.kotlin.services.dynamodb.waiters.waitUntilTableExists
import kotlin.system.exitProcess
// snippet-end:[dynamodb.kotlin.create_table.import]

/**
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(args: Array<String>) {
val usage = """
Usage:
<tableName> <key>
Where:
tableName - The Amazon DynamoDB table to create (for example, Music3).
key - The key for the Amazon DynamoDB table (for example, Artist).
"""

if (args.size != 2) {
println(usage)
exitProcess(0)
}

val tableName = args[0]
val key = args[1]
println("Creating an Amazon DynamoDB table named $tableName with a key named $key")
val tableArn = createNewTable(tableName, key)
println("The new table ARN is $tableArn")
}

// snippet-start:[dynamodb.kotlin.create_table.main]
suspend fun createNewTable(tableNameVal: String, key: String): String? {
val attDef = AttributeDefinition {
attributeName = key
attributeType = ScalarAttributeType.S
}

val keySchemaVal = KeySchemaElement {
attributeName = key
keyType = KeyType.Hash
}

val provisionedVal = ProvisionedThroughput {
readCapacityUnits = 10
writeCapacityUnits = 10
}

val request = CreateTableRequest {
attributeDefinitions = listOf(attDef)
keySchema = listOf(keySchemaVal)
provisionedThroughput = provisionedVal
tableName = tableNameVal
}

DynamoDbClient { region = "us-east-1" }.use { ddb ->

var tableArn: String
val response = ddb.createTable(request)
ddb.waitUntilTableExists { // suspend call
tableName = tableNameVal
}
tableArn = response.tableDescription!!.tableArn.toString()
println("Table $tableArn is ready")
return tableArn
}
}
// snippet-end:[dynamodb.kotlin.create_table.main]
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.dynamodb

// snippet-start:[dynamodb.kotlin.create_table.import]
import aws.sdk.kotlin.services.dynamodb.DynamoDbClient
import aws.sdk.kotlin.services.dynamodb.model.AttributeDefinition
import aws.sdk.kotlin.services.dynamodb.model.CreateTableRequest
import aws.sdk.kotlin.services.dynamodb.model.KeySchemaElement
import aws.sdk.kotlin.services.dynamodb.model.KeyType
import aws.sdk.kotlin.services.dynamodb.model.ProvisionedThroughput
import aws.sdk.kotlin.services.dynamodb.model.ScalarAttributeType
import aws.sdk.kotlin.services.dynamodb.waiters.waitUntilTableExists
import kotlin.system.exitProcess
// snippet-end:[dynamodb.kotlin.create_table.import]

/**
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(args: Array<String>) {
val usage = """
Usage:
<tableName> <key>
Where:
tableName - The Amazon DynamoDB table to create (for example, Music3).
key - The key for the Amazon DynamoDB table (for example, Artist).
"""

if (args.size != 2) {
println(usage)
exitProcess(0)
}

val tableName = args[0]
val key = args[1]
println("Creating an Amazon DynamoDB table named $tableName with a key named $key")
val tableArn = createNewTable(tableName, key)
println("The new table ARN is $tableArn")
}

// snippet-start:[dynamodb.kotlin.create_table.main]
suspend fun createNewTable(
tableNameVal: String,
key: String
): String? {
val attDef =
AttributeDefinition {
attributeName = key
attributeType = ScalarAttributeType.S
}

val keySchemaVal =
KeySchemaElement {
attributeName = key
keyType = KeyType.Hash
}

val provisionedVal =
ProvisionedThroughput {
readCapacityUnits = 10
writeCapacityUnits = 10
}

val request =
CreateTableRequest {
attributeDefinitions = listOf(attDef)
keySchema = listOf(keySchemaVal)
provisionedThroughput = provisionedVal
tableName = tableNameVal
}

DynamoDbClient { region = "us-east-1" }.use { ddb ->
var tableArn: String
val response = ddb.createTable(request)
ddb.waitUntilTableExists {
// suspend call
tableName = tableNameVal
}
tableArn = response.tableDescription!!.tableArn.toString()
println("Table $tableArn is ready")
return tableArn
}
}
// snippet-end:[dynamodb.kotlin.create_table.main]
Original file line number Diff line number Diff line change
@@ -1,58 +1,63 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.dynamodb

// snippet-start:[dynamodb.kotlin.delete_item.import]
import aws.sdk.kotlin.services.dynamodb.DynamoDbClient
import aws.sdk.kotlin.services.dynamodb.model.AttributeValue
import aws.sdk.kotlin.services.dynamodb.model.DeleteItemRequest
import kotlin.system.exitProcess
// snippet-end:[dynamodb.kotlin.delete_item.import]

/**
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(args: Array<String>) {
val usage = """
Usage:
<tableName> <key> <keyval>
Where:
tableName - The Amazon DynamoDB table to delete the item from (for example, Music3).
key - The key used in the Amazon DynamoDB table (for example, Artist).
keyval - The key value that represents the item to delete (for example, Famous Band).
"""

if (args.size != 3) {
println(usage)
exitProcess(0)
}

val tableName = args[0]
val key = args[1]
val keyVal = args[2]
deleteDynamoDBItem(tableName, key, keyVal)
}

// snippet-start:[dynamodb.kotlin.delete_item.main]
suspend fun deleteDynamoDBItem(tableNameVal: String, keyName: String, keyVal: String) {
val keyToGet = mutableMapOf<String, AttributeValue>()
keyToGet[keyName] = AttributeValue.S(keyVal)

val request = DeleteItemRequest {
tableName = tableNameVal
key = keyToGet
}

DynamoDbClient { region = "us-east-1" }.use { ddb ->
ddb.deleteItem(request)
println("Item with key matching $keyVal was deleted")
}
}
// snippet-end:[dynamodb.kotlin.delete_item.main]
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.kotlin.dynamodb

// snippet-start:[dynamodb.kotlin.delete_item.import]
import aws.sdk.kotlin.services.dynamodb.DynamoDbClient
import aws.sdk.kotlin.services.dynamodb.model.AttributeValue
import aws.sdk.kotlin.services.dynamodb.model.DeleteItemRequest
import kotlin.system.exitProcess
// snippet-end:[dynamodb.kotlin.delete_item.import]

/**
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(args: Array<String>) {
val usage = """
Usage:
<tableName> <key> <keyval>
Where:
tableName - The Amazon DynamoDB table to delete the item from (for example, Music3).
key - The key used in the Amazon DynamoDB table (for example, Artist).
keyval - The key value that represents the item to delete (for example, Famous Band).
"""

if (args.size != 3) {
println(usage)
exitProcess(0)
}

val tableName = args[0]
val key = args[1]
val keyVal = args[2]
deleteDynamoDBItem(tableName, key, keyVal)
}

// snippet-start:[dynamodb.kotlin.delete_item.main]
suspend fun deleteDynamoDBItem(
tableNameVal: String,
keyName: String,
keyVal: String
) {
val keyToGet = mutableMapOf<String, AttributeValue>()
keyToGet[keyName] = AttributeValue.S(keyVal)

val request =
DeleteItemRequest {
tableName = tableNameVal
key = keyToGet
}

DynamoDbClient { region = "us-east-1" }.use { ddb ->
ddb.deleteItem(request)
println("Item with key matching $keyVal was deleted")
}
}
// snippet-end:[dynamodb.kotlin.delete_item.main]
Loading

0 comments on commit 6056394

Please sign in to comment.