wirthan / s3dsl

Tagless Final wrapper around a subset of aws-java-sdk-s3



Release Artifacts

Minimal, stream based S3 DSL. Depends on aws-java-sdk-s3.

Getting s3dsl

If you're using SBT, add the following line to your build file:

libraryDependencies += "com.github.wirthan" %% "s3dsl" % <version>

Quick Start

Initialize an interpreter

s3dsl provides a function that returns a cats-effect interpreter:

import s3dsl.S3Dsl._
import s3dsl.domain.S3._

val config = S3Config(
  creds = new BasicAWSCredentials("BQKN8G6V2DQ83DH3AHPN", "GPD7MUZqy6XGtTz7h2QPyJbggGkQfigwDnaJNrgF"),
  endpoint = new EndpointConfiguration("http://localhost:9000", "us-east-1"),
  blockingEc = ExecutionContext.fromExecutor(Executors.newCachedThreadPool)

val cs = IO.contextShift(ExecutionContext.fromExecutor(Executors.newFixedThreadPool(3)))
val s3 = interpreter(config, cs)(IO.ioConcurrentEffect(cs))

Use the interpreter

val path = Path(BucketName("mybucket"), Key("blob.txt"))
val blob = "abc".getBytes

// S3.Object consists of Stream[IO, Byte] and ObjectMetadata
val obj: Option[S3.Object[IO]] = for {
  _ <- Stream.emits(blob).covary[IO]
        .to(s3.putObject(path, blob.length.longValue))
  obj <- s3.getObject(path, 1024)      
} yield obj