Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
52 lines (40 sloc) 1.56 KB
import org.http4k.client.ApacheClient
import org.http4k.core.Method.GET
import org.http4k.core.Method.PUT
import org.http4k.core.Request
import org.http4k.core.Uri
import org.http4k.core.then
import org.http4k.filter.AwsAuth
import org.http4k.filter.ClientFilters
import java.util.UUID
fun main() {
val region = "us-east-1"
val service = "s3"
val accessKey = "myGreatAwsAccessKey"
val secretKey = "myGreatAwsSecretKey"
val client = ClientFilters.AwsAuth(
AwsCredentialScope(region, service),
AwsCredentials(accessKey, secretKey))
// create a bucket
val bucketName = UUID.randomUUID().toString()
val bucketUri = Uri.of("https://$")
println(client(Request(PUT, bucketUri)))
// get list of buckets with the new bucket in it
println(client(Request(GET, Uri.of(""))).bodyString())
// create a key into the bucket
val key = UUID.randomUUID().toString()
val keyUri = Uri.of("https://$$key")
println(client(Request(PUT, keyUri).body("some amazing content that I want stored on S3")))
// get the keys in the bucket
println(client(Request(GET, bucketUri)))
// get the contents of the key in the bucket
println(client(Request(GET, keyUri)))
// delete the key in the bucket
println(client(Request(GET, keyUri)))
// delete the bucket
println(client(Request(GET, bucketUri)))