Skip to content

Commit

Permalink
chore: Update README with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfarrell committed Jul 11, 2018
1 parent 27bdd74 commit 7b5022c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
36 changes: 33 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,48 @@ This library encapsulates does that for you using rx-kotlin.

Failed writes are retried up until the attempt limit is reached using exponential backoff with jitter.

For refernence, [github link to issue](https://github.com/aws/aws-sdk-js/issues/1262)
For details on exponential backoff and jitter in aws see [her](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/)

### Examples
```
```kotlin

data class Person(val name:String, val address: String)

class PersonMapper : DynamoMapper<Person> {
override fun mapToDynamoItem(person: Person): Map<String, AttributeValue> {
return mapOf(Pair("name", AttributeValue(person.name)),
Pair("address", AttributeValue(person.address)))
}
}

val amazonDynamoDB: AmazonDynamoDB = ...

val dyanmoBatch: DynamoBatchExecutor<Person> = DynamoBatchExecutor<Person> (amazonDynamoDB)

dynamoBatch.persist(listOf(Person("bob", "France"), Person("jack", "Dublin")), PersonMapper(), "targetTable")


```

For refernence, [github link to issue](https://github.com/aws/aws-sdk-js/issues/1262)
For details on exponential backoff and jitter in aws see [her](https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/)

## DynamoTableCloner

This library allows you to clone a dynamo table, including hash and sort key,local and secondary indexes, provisioned throughput settings, dynamo streaming even source mappings and autoscaling properties if defined.
The library also exposes functions that return the aws sdk requests that would create all of the above without applying them so that tables can be partially cloned, and also streaming event sources or autoscaling properties from one table to
be applied to another

### Examples
```kotlin

// You can create your own clients as necessary, the default is to use the standard client.
val amazonDynamoDB: AmazonDynamoDB = ...
val awsLambdaClient: AWSLambdaClient = ...
val autoScalingClient: AWSApplicationAutoScaling = ...

val dynamoTableCloner: DynamoTableCloner = DynamoTableCloner(amazonDynamoDB, awsLambdaClient, autoScalingClient)

dynamoTableCloner.cloneTable("template", "target")

// You now have a new table called "target"
```
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ open class DynamoBatchExecutor<T>(private val amazonDynamoDB: AmazonDynamoDB = A
private val scheduler: Scheduler = Schedulers.io(),
private val random: Random = Random(),
private val initialBackoffMs: Long = 1000,
private val attemptLimit: Long?
private val attemptLimit: Long? = null
) {

/**
Expand All @@ -42,6 +42,7 @@ open class DynamoBatchExecutor<T>(private val amazonDynamoDB: AmazonDynamoDB = A
batchPersist(writeRequests)
}


/**
* Batch persist the [items] to table [tableName] where [mapper] converts objects of type [T] to Map<String, AttributeValue>
*/
Expand Down

0 comments on commit 7b5022c

Please sign in to comment.