Skip to main content

Interacting with Buckets

To create a bucket we can use the createBucket method. For this method and all others here, please refer to the S3 Documentation for additional optional headers than can be included in the method.

In this example, a new bucket is made called "hello-world-bucket-example" with an additional header added that sets the ACL to public-read, allowing all users other than the owner read access. The owner is given full control permissions over the bucket.

import org.http4s.{Header, Headers}

s3.createBucket(
"hello-world-bucket-example",
Headers(Header("x-amz-acl", "public-read")))
// res0: IO[CreateBucketResponse] = IO$226961932

To delete a bucket, call the deleteBucket method. The user must have the required permissions to complete this action.

s3.deleteBucket("hello-world-bucket-example")
// res1: IO[Headers] = IO$1569746307

To list all buckets available to the user, use the listBuckets method.

def printBucket(bucket: Bucket): IO[Unit] = IO {
println(s"Bucket Name: ${bucket.name}, Creation Date: ${bucket.creationDate}")
}

s3.listBuckets().flatMap{ response => response.buckets.traverse(printBucket _) }
// res2: IO[Vector[Unit]] = IO$465909321