Skip to main content
Version: 2.x

Getting Started

Add the dependency to your build.sbt file​

libraryDependencies += "dev.zio" %% "zio-dynamodb" % 1.0.0-RC18

Read & write data to/from DynamoDB​

import zio.aws.core.config
import zio.aws.{ dynamodb, netty }
import zio.dynamodb.DynamoDBQuery.{ get, put }
import zio.dynamodb.{ DynamoDBExecutor }
import zio.schema.{ DeriveSchema, Schema }
import zio.ZIOAppDefault
import zio.dynamodb.ProjectionExpression

object Main extends ZIOAppDefault {

final case class Person(id: Int, firstName: String)
object Person {
implicit lazy val schema: Schema.CaseClass2[Int, String, Person] = DeriveSchema.gen[Person]

val (id, firstName) = ProjectionExpression.accessors[Person]
}
val examplePerson = Person(1, "avi")

private val program = for {
_ <- put("personTable", examplePerson).execute
person <- get("personTable")(Person.id.partitionKey === 1).execute
_ <- zio.Console.printLine(s"hello $person")
} yield ()

override def run =
program.provide(
netty.NettyHttpClient.default,
config.AwsConfig.default, // uses real AWS dynamodb
dynamodb.DynamoDb.live,
DynamoDBExecutor.live
)
}