From 2b47cefdf9a68bc460d3f7eb9d57d9181ead1ff2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estiven=20S=C3=A1nchez?= Date: Mon, 27 Nov 2023 21:34:24 -0500 Subject: [PATCH 1/3] Update documentation --- .github/workflows/documentation.yml | 4 +- doc/Writerside/akm.tree | 1 + doc/Writerside/topics/Default-topic.md | 1 + doc/Writerside/topics/DynamoDB.md | 172 +++++++++++++++++++++++++ doc/Writerside/writerside.cfg | 2 +- 5 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 doc/Writerside/topics/DynamoDB.md diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 0c988a0..883f6f5 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -15,7 +15,7 @@ env: jobs: build-documentation: - #if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/') + if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/') runs-on: ubuntu-latest steps: - name: Checkout repository @@ -62,7 +62,7 @@ jobs: instance: ${{ env.INSTANCE }} deploy-documentation: - # if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/') + if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/') environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} diff --git a/doc/Writerside/akm.tree b/doc/Writerside/akm.tree index 033cd89..14df014 100644 --- a/doc/Writerside/akm.tree +++ b/doc/Writerside/akm.tree @@ -8,5 +8,6 @@ start-page="Default-topic.md"> + \ No newline at end of file diff --git a/doc/Writerside/topics/Default-topic.md b/doc/Writerside/topics/Default-topic.md index 6c1801c..048d516 100644 --- a/doc/Writerside/topics/Default-topic.md +++ b/doc/Writerside/topics/Default-topic.md @@ -8,4 +8,5 @@ If you want to re-add it for your experiments, click + to create a new topic, ch
  • S3
  • +
  • DynamoDB
  • diff --git a/doc/Writerside/topics/DynamoDB.md b/doc/Writerside/topics/DynamoDB.md new file mode 100644 index 0000000..3cd7959 --- /dev/null +++ b/doc/Writerside/topics/DynamoDB.md @@ -0,0 +1,172 @@ +# DynamoDB + + + +The following code examples show you how to perform actions and implement common scenarios by using the AWS SDK for Kotlin with DynamoDB. + +Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios and cross-service examples. + +Scenarios are code examples that show you how to accomplish a specific task by calling multiple functions within the same service. + +Each example includes a link to GitHub, where you can find instructions on how to set up and run the code in context. + +## Configuration + + +
  • Add dependency in module shared/build.gradle.kts + +val commonMain by getting { + dependencies { + implementation("io.github.estivensh4:aws-dynamo:$lastVersion") + } +} + +
  • +
  • Add pod in module shared/build.gradle.kts + +cocoapods { + summary = "Some description for the Shared Module" + homepage = "Link to the Shared Module homepage" + version = "1.0" + ios.deploymentTarget = "14.1" + framework { + baseName = "shared" + } + pod("AWSDynamoDB", "~> 2.33.4") // add this line +} + +
  • +
  • Add pod in iosApp/Podfile + +target 'iosApp' do + use_frameworks! + platform :ios, '14.1' + pod 'shared', :path => '../shared' + pod 'AWSDynamoDB', '~> 2.33.4' # add this line +end + +
  • +
    + +## Examples +### Configure client + +val builder = AWSBuilder() + .accessKey("YOUR_ACCESS_KEY") + .secretKey("YOUR_SECRET_KEY") +client = builder.buildDynamo() + + +### Create table + +val request = CreateTableRequest( + tableName = tableName, + keySchemaList = listOf( + KeySchemaElement( + attributeName = "year", + keyType = KeyType.HASH + ), + KeySchemaElement( + attributeName = "title", + keyType = KeyType.RANGE + ) + ), + attributeDefinitions = listOf( + AttributeDefinition( + attributeName = "year", + attributeType = ScalarAttributeType.N + ), + AttributeDefinition( + attributeName = "title", + attributeType = ScalarAttributeType.S + ) + ) +) + +val result = client.createTable(request) + + +### Put item + +val result = client.putItem( + tableName = tableName, + items = mapOf( + "year" to AttributeValue.Builder().withN("6").build(), + "title" to AttributeValue.Builder().withS("Title").build(), + "customerId" to AttributeValue.Builder().withS("1").build(), + "emailAddress" to AttributeValue.Builder().withS("test@test.com").build(), + "firstName" to AttributeValue.Builder().withS("Test").build(), + "lastName" to AttributeValue.Builder().withS("Test").build() + ) +) + + +### Get all tables + +val result = client.getAllTables() + + +### Get item + +val result = client.getItem( + tableName = tableName, + items = mapOf( + "year" to AttributeValue.Builder().withN(n).build(), + "title" to AttributeValue.Builder().withS(title).build(), + ) +) + + +### Delete item + +val result = client.deleteItem( + tableName = tableName, + items = mapOf( + "year" to AttributeValue.Builder().withN(n).build(), + "title" to AttributeValue.Builder().withS(title).build(), + ) +) + + +### Query item + +val desiredYear = 10 +val result = client.query( + QueryRequest.Builder() + .withTableName(tableName) + .withKeyConditionExpression("#yr = :yearValue") + .withExpressionAttributeNames(mapOf("#yr" to "year")) + .withExpressionAttributeValues( + mapOf( + ":yearValue" to AttributeValue.Builder().withN(desiredYear.toString()).build() + ) + ) + .build() +) + + +### Scan item + +val result = client.scan( + ScanRequest.Builder() + .withTableName(tableName) + .build() +) + + +### Update item + +val year = 5 +val title = "Title" +val result = client.updateItem( + tableName = tableName, + keys = mapOf( + "year" to AttributeValue.Builder().withN(year.toString()).build(), + "title" to AttributeValue.Builder().withS(title).build() + ), + attributeValueUpdate = mapOf( + "customerId" to AttributeValueUpdate.Builder() + .withValue(AttributeValue.Builder().withS("Mario").build()).build() + ) +) + \ No newline at end of file diff --git a/doc/Writerside/writerside.cfg b/doc/Writerside/writerside.cfg index de3a88d..c1955b4 100644 --- a/doc/Writerside/writerside.cfg +++ b/doc/Writerside/writerside.cfg @@ -6,5 +6,5 @@ - + \ No newline at end of file From e169a157e4bfa407c019b2180b549062a587110a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estiven=20S=C3=A1nchez?= Date: Mon, 27 Nov 2023 21:36:18 -0500 Subject: [PATCH 2/3] Update documentation.yml --- .github/workflows/documentation.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 883f6f5..7e06568 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -15,7 +15,7 @@ env: jobs: build-documentation: - if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/') + #if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/') runs-on: ubuntu-latest steps: - name: Checkout repository @@ -45,7 +45,7 @@ jobs: retention-days: 7 test-documentation: - if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/') + #if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/') needs: build-documentation runs-on: ubuntu-latest @@ -62,7 +62,7 @@ jobs: instance: ${{ env.INSTANCE }} deploy-documentation: - if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/') + #if: github.event_name == 'pull_request' && github.event.action == 'opened' && startsWith(github.event.pull_request.head.ref, 'samples/') environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} From f3a847eb98328fd95b9d82f9798fab9fe52c316d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estiven=20S=C3=A1nchez?= Date: Mon, 27 Nov 2023 21:55:33 -0500 Subject: [PATCH 3/3] Update dynamodb.md --- doc/Writerside/topics/DynamoDB.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/Writerside/topics/DynamoDB.md b/doc/Writerside/topics/DynamoDB.md index 3cd7959..1deecf3 100644 --- a/doc/Writerside/topics/DynamoDB.md +++ b/doc/Writerside/topics/DynamoDB.md @@ -58,7 +58,7 @@ client = builder.buildDynamo() ### Create table - +```Kotlin val request = CreateTableRequest( tableName = tableName, keySchemaList = listOf( @@ -84,7 +84,7 @@ val request = CreateTableRequest( ) val result = client.createTable(request) - +``` ### Put item