Using AWS SDK on the Scala REPL
Scala Shell
Latest commit 7c90c5b Aug 20, 2016 @seratch version 0.5.7

AWScala: AWS SDK on the Scala REPL

Build Status Maven Central

AWScala enables Scala developers to easily work with Amazon Web Services in the Scala way.

Though AWScala objects basically extend AWS SDK for Java APIs, you can use them with less stress on Scala REPL or sbt console.

Supported Services

  • AWS Identity and Access Management (IAM)
  • AWS Security Token Service (STS)
  • Amazon Elastic Compute Cloud (Amazon EC2)
  • Amazon Simple Storage Service (Amazon S3)
  • Amazon Simple Queue Service(Amazon SQS)
  • Amazon Redshift
  • Amazon DynamoDB
  • Amazon SimpleDB

How to use

Latest version

libraryDependencies += "com.github.seratch" %% "awscala" % "0.5.+"

AWS Java SDK 1.8.x compatible

libraryDependencies += "com.github.seratch" %% "awscala" % "0.3.+"

Configure credentials in the AWS Java SDK way.


AWS Identity and Access Management (IAM)

import awscala._, iam._
implicit val iam = IAM()

val group = iam.createGroup("Developers")

import awscala.auth.policy._
  Policy(Seq(Statement(Effect.Allow, Seq(Action("s3:*")), Seq(Resource("*"))))))

val user: User = iam.createUser("Alice")

group.policyNames.foreach(name => group.policy(name).destroy())

AWS Security Token Service (STS)
import awscala._, sts._

implicit val sts = STS()

val federation: FederationToken = sts.federationToken(
  name = "anonymous-user",
  policy = Policy(Seq(Statement(Effect.Allow, Seq(Action("s3:*")), Seq(Resource("*"))))),
  durationSeconds = 1200)

val signinToken: String = sts.signinToken(federation.credentials)

val loginUrl: String = sts.loginUrl(
  credentials = federation.credentials,
  consoleUrl  = "",
  issuerUrl   = "")

Amazon Elastic Compute Cloud (Amazon EC2)

import awscala._, ec2._

implicit val ec2 =

val existings: Seq[Instance] = ec2.instances

import scala.concurrent._

// simply create a t1.micro instance
val f = Future(ec2.runAndAwait("ami-2819aa29", ec2.keyPairs.head))

for {
  instances <- f
  instance <- instances
} {
  instance.withKeyPair(new"key_pair_file")) { i =>
    // optional: scala-ssh (
    i.ssh { ssh =>
      ssh.exec("ls -la") { result =>
        println(s"------\n${inst.instanceId} Result:\n" + result.stdOutAsString())

Amazon Simple Storage Service (Amazon S3)

import awscala._, s3._

implicit val s3 = S3()

val buckets: Seq[Bucket] = s3.buckets
val bucket: Bucket = s3.createBucket("unique-name-xxx")
val summaries: Seq[S3ObjectSummary] = bucket.objectSummaries

bucket.put("sample.txt", new"sample.txt"))

val s3obj: Option[S3Object] = bucket.getObject("sample.txt")

s3obj.foreach { obj =>
  obj.publicUrl //
  obj.generatePresignedUrl( // ?Expires=....
  bucket.delete(obj) // or obj.destroy()

Amazon Simple Queue Service(Amazon SQS)

import awscala._, sqs._
implicit val sqs =

val queue: Queue = sqs.createQueue("sample-queue")

queue.add("message body")
queue.add("first", "second", "third")

val messages: Seq[Message] = queue.messages


Amazon Redshift

import awscala._, redshift._

implicit val redshift =

val cluster: Cluster = redshift.createCluster(NewCluster(
  "sample-cluster", "mydb", "username", "password"))

val snapshot: Snapshot = redshift.createSnapshot(cluster, "snapshot-name") 

redshift.delete(cluster, "final-snapshot-name")

Amazon DynamoDB

import awscala._, dynamodbv2._

implicit val dynamoDB =

val tableMeta: TableMeta = dynamoDB.createTable(
  name = "Members",
  hashPK =  "Id" -> AttributeType.Number,
  rangePK = "Country" -> AttributeType.String,
  otherAttributes = Seq("Company" -> AttributeType.String),
  indexes = Seq(LocalSecondaryIndex(
    name = "CompanyIndex",
    keySchema = Seq(KeySchema("Id", KeyType.Hash), KeySchema("Company", KeyType.Range)),
    projection = Projection(ProjectionType.Include, Seq("Company"))

val table: Table = dynamoDB.table("Members").get

table.put(1, "Japan", "Name" -> "Alice", "Age" -> 23, "Company" -> "Google")
table.put(2, "U.S.",  "Name" -> "Bob",   "Age" -> 36, "Company" -> "Google")
table.put(3, "Japan", "Name" -> "Chris", "Age" -> 29, "Company" -> "Amazon")

val googlers: Seq[Item] = table.scan(Seq("Company" ->"Google")))


Amazon SimpleDB

import awscala._, simpledb._

implicit val simpleDB =

val domain: Domain = simpleDB.createDomain("users")

domain.put("00001", "name" -> "Alice", "age" -> "23", "country" -> "America")
domain.put("00002", "name" -> "Bob",   "age" -> "34", "country" -> "America")
domain.put("00003", "name" -> "Chris", "age" -> "27", "country" -> "Japan")

val items: Seq[Item] ="select * from users where country = 'America'")

Amazon Elastic MapReduce (Amazon EMR)

Created by @CruncherBigData. If you have any feedback or questions, please contact @CruncherBigData.

How to contribute

If you're interested in contributing this project, please send pull requests!

Running tests

Tests require aws credentials with Administrator permissions:

export AWS_ACCESS_KEY_ID=xxx

The DynamoDB tests also require a locally running instance of DynamoDB. An install script is provided as bin/installDynamoDbLocal. A launch script is provided as bin/runDynamoDbLocal. See for more info.

To run the tests, just type sbt test.


Copyright 2013 - 2014 AWScala Developers

Apache License, Version 2.0