• This repository has been archived on 13/Jun/2023
  • Stars
    star
    737
  • Rank 59,550 (Top 2 %)
  • Language
    Scala
  • License
    Other
  • Created almost 11 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Using AWS SDK on the Scala REPL

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

http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/

  • 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
  • AWS Step Functions

How to use

To pull in all modules:

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

To pull in only selected modules:

libraryDependencies ++= Seq(
    "com.github.seratch" %% "awscala-ec2" % "0.9.+",
    "com.github.seratch" %% "awscala-iam" % "0.9.+",
    "com.github.seratch" %% "awscala-dynamodb" % "0.9.+",
    "com.github.seratch" %% "awscala-emr" % "0.9.+",
    "com.github.seratch" %% "awscala-redshift" % "0.9.+",
    "com.github.seratch" %% "awscala-s3" % "0.9.+",
    "com.github.seratch" %% "awscala-simpledb" % "0.9.+",
    "com.github.seratch" %% "awscala-sqs" % "0.9.+",
    "com.github.seratch" %% "awscala-sts" % "0.9.+",
    "com.github.seratch" %% "awscala-stepfunctions" % "0.9.+"
)

Configure credentials in the AWS Java SDK way.

http://docs.aws.amazon.com/AWSSdkDocsJava/latest/DeveloperGuide/credentials.html

Examples

AWS Identity and Access Management (IAM)

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

val group = iam.createGroup("Developers")

group.putPolicy("policy-name", 
  Policy(Seq(Statement(Effect.Allow, Seq(Action("s3:*")), Seq(Resource("*"))))))

val user: User = iam.createUser("Alice")
user.setLoginPassword("password")
group.add(user)

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

https://github.com/seratch/AWScala/blob/master/iam/src/main/scala/awscala/iam/IAM.scala

https://github.com/seratch/awscala/blob/master/iam/src/test/scala/awscala/IAMSpec.scala

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  = "https://console.aws.amazon.com/iam",
  issuerUrl   = "http://example.com/internal/auth")

https://github.com/seratch/awscala/blob/master/sts/src/main/scala/awscala/sts/STS.scala

https://github.com/seratch/awscala/blob/master/sts/src/test/scala/awscala/STSSpec.scala

Amazon Elastic Compute Cloud (Amazon EC2)

import awscala._, ec2._

implicit val ec2 = EC2.at(Region.Tokyo)

val existings: Seq[Instance] = ec2.instances

import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global

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

for {
  instances <- f
  instance <- instances
} {
  instance.withKeyPair(new java.io.File("key_pair_file")) { i =>
    // optional: scala-ssh (https://github.com/sirthias/scala-ssh)
    i.ssh { ssh =>
      ssh.exec("ls -la").right.map { result =>
        println(s"------\n${inst.instanceId} Result:\n" + result.stdOutAsString())
      }
    }
  }
  instance.terminate()
}

https://github.com/seratch/awscala/blob/master/ec2/src/main/scala/awscala/ec2/EC2.scala

https://github.com/seratch/awscala/blob/master/ec2/src/test/scala/awscala/EC2Spec.scala

Amazon Simple Storage Service (Amazon S3)

import awscala._, s3._

implicit val s3 = S3.at(Region.Tokyo)

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 java.io.File("sample.txt"))

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

s3obj.foreach { obj =>
  obj.publicUrl // http://unique-name-xxx.s3.amazonaws.com/sample.txt
  obj.generatePresignedUrl(DateTime.now.plusMinutes(10)) // ?Expires=....
  bucket.delete(obj) // or obj.destroy()
}

https://github.com/seratch/awscala/blob/master/s3/src/main/scala/awscala/s3/S3.scala

https://github.com/seratch/awscala/blob/master/s3/src/test/scala/awscala/S3Spec.scala

Amazon Simple Queue Service(Amazon SQS)

import awscala._, sqs._
implicit val sqs = SQS.at(Region.Tokyo)

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

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

val messages: Seq[Message] = queue.messages
queue.removeAll(messages)

queue.destroy()

https://github.com/seratch/awscala/blob/master/sqs/src/main/scala/awscala/sqs/SQS.scala

https://github.com/seratch/awscala/blob/master/sqs/src/test/scala/awscala/SQSSpec.scala

Amazon Redshift

import awscala._, redshift._

implicit val redshift = Redshift.at(Region.Tokyo)

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")

https://github.com/seratch/awscala/blob/master/redshift/src/main/scala/awscala/redshift/Redshift.scala

Amazon DynamoDB

import awscala._, dynamodbv2._ 

implicit val dynamoDB = DynamoDB.at(Region.Tokyo)

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" -> cond.eq("Google")))

table.destroy()

PUT method with case class usage (@hashPK and @rangePK annotations are not currently available in Scala 3)

import awscala._, dynamodbv2._ 

implicit val dynamoDB = DynamoDB.at(Region.Tokyo)

case class Member(Name: String, Age: Int, Company: String)
case class TestMember(
     @hashPK id: Int,
     @rangePK country: String,
     company: String,
     name: String,
     age: Int)
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
val member = Member("Alex", 29, "DataMass")
table.putItem(1, "PL", member)

// putItem() allows you to push the whole case class object with hashPK and rangePK included
val user = TestMember(2,"PL", "Jakub", 33, "DataMass")
table.putItem(user)

val members: Seq[Item] = table.scan(Seq("Company" -> cond.eq("DataMass")))
table.destroy()

https://github.com/seratch/awscala/blob/master/dynamodb/src/main/scala/awscala/dynamodbv2/DynamoDB.scala

https://github.com/seratch/awscala/blob/master/dynamodb/src/test/scala/awscala/DynamoDBV2Spec.scala

Amazon SimpleDB

import awscala._, simpledb._

implicit val simpleDB = SimpleDB.at(Region.Tokyo)

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] = domain.select(s"select * from users where country = 'America'")

simpleDB.domains.foreach(_.destroy())

https://github.com/seratch/awscala/blob/master/simpledb/src/main/scala/awscala/simpledb/SimpleDB.scala

https://github.com/seratch/awscala/blob/master/simpledb/src/test/scala/awscala/SimpleDBSpec.scala

AWS Step Functions

import awscala._, stepfunctions._

implicit val steps = StepFunctions.at(Region.Tokyo)

val machineDefinition = "{ ... state machine definition ... }"
val role = Role(...)

val machine = steps.createStateMachine("myMachine", machineDefinition, role)
val activity = steps.createActivity("MyActivity")
val exec = machine.startExecution("machine input")

steps.runActivity(activity.name) { input => s"Received input $input" }

exec.stepStatus("Some Step")
val history: Seq[ExecutionEvent] = exec.history()
val status = exec.status()

machine.delete()
activity.delete()

https://github.com/seratch/awscala/blob/master/stepfunctions/src/main/scala/awscala/stepfunctions/StepFunctions.scala

https://github.com/seratch/awscala/blob/master/stepfunctions/src/test/scala/awscala/StepFunctionsSpec.scala

Amazon Elastic MapReduce (Amazon EMR)

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

https://github.com/seratch/awscala/blob/master/emr/src/main/scala/awscala/emr/EMR.scala

https://github.com/seratch/awscala/blob/master/emr/src/test/scala/awscala/EMRSpec.scala

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
export AWS_SECRET_ACCESS_KEY=yyy

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 http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tools.DynamoDBLocal.html for more info.

To run the tests, just type sbt test.

License

Copyright 2013 - AWScala Developers

Apache License, Version 2.0

More Repositories

1

ChatGPT-in-Slack

Swift demonstration of how to build a Slack app that enables end-users to interact with a ChatGPT bot
Python
385
star
2

gistub

Sharing code snippets in-house
Ruby
242
star
3

kotliquery

A handy Database access library in Kotlin
Kotlin
193
star
4

deepl-for-slack

Slack app for DeepL Translate API users
TypeScript
143
star
5

notion-sdk-jvm

A Notion SDK for Any JVM Language
Kotlin
130
star
6

rspec-kickstarter

RSpec 3 code generator toward existing Ruby code.
Ruby
128
star
7

notion-translator

CLI tool to translate Notion pages into a different language
JavaScript
65
star
8

slack-edge

Slack app development framework for edge functions with streamlined TypeScript support
TypeScript
60
star
9

slack-app-examples

A collection of Slack App examples
TypeScript
59
star
10

slack-cloudflare-workers

Slack app development framework for Cloudflare Workers
TypeScript
57
star
11

bolt-starter

A Bolt ⚡️ app template with useful settings for easier development
JavaScript
52
star
12

scalikesolr

Apache Solr Client for Scala/Java
Scala
51
star
13

chatgpt-on-deno

ChatGPT on Slack's next-gen modular platform
TypeScript
49
star
14

serverless-slack-bolt-aws

Read this issue first - https://github.com/slackapi/bolt/issues/361
JavaScript
43
star
15

bigquery4s

A handy Scala wrapper of Google BigQuery API 's Java Client Library.
Scala
34
star
16

slack-bolt-extensions

Collection of bolt-js InstallationStore/Receiver implementations + Next.js support module
TypeScript
33
star
17

apriori.js

Apriori Algorithm implementation in TypeScript|JavaScript
JavaScript
30
star
18

junithelper

JUnit testing without dull routine
Java
30
star
19

apriori4j

Apriori Algorithm Implementation in Java, Scala
Java
26
star
20

slack-web-api-client

Streamlined Slack Web API client for TypeScript
TypeScript
25
star
21

bolt-on-cloud-functions-for-firebase

Read this issue first - https://github.com/slackapi/bolt/issues/361
JavaScript
24
star
22

finagle-cluster-demo

Finagle Hack-a-thon at Twitter Japan @yakitori
JavaScript
22
star
23

slack-timesheet

Timesheet, a Slack automation platform app for managing work hours
TypeScript
21
star
24

bit-valley-2020-slack-bolt-app

これは BIT VALLEY 2020 でのプレゼンテーション用のデモアプリです。インタラクティブな機能を使ったサンプルとして是非参考にしてみてください! https://git.io/BV_2020_Slack
JavaScript
20
star
25

bolt-on-heroku

Bolt example app in TypeScript on Heroku
TypeScript
16
star
26

slack_learning_app_ja

Slack プラットフォームの機能を学習するためのチュートリアルアプリ
Python
16
star
27

run-on-slack-template

"run-on-slack" app template
TypeScript
16
star
28

seratch-slack-types

Slack API TypeScript types generated by @seratch
TypeScript
15
star
29

inputvalidator

Scala Input Validator with quite readable DSL
Scala
15
star
30

slack-api-workshop-in-fukuoka-2019

Slack API workshop for Japanese developers
JavaScript
14
star
31

sadamasashi-compiler

さだまさしコンパイラ
Scala
14
star
32

slack-weather-radar-map

Japan Weather Radar Map (雨雲レーダー) on Slack ⛈️
TypeScript
13
star
33

deno-slack-data-mapper

A handy way to manage data in Slack's next-generation platform datastores
TypeScript
12
star
34

nhk4s

"NHK 番組表 API" client library for Scala
Scala
12
star
35

r2dbc-samples-in-scala

Demonstrates how to use R2DBC - Reactive Relational Database Connectivity in Scala
Scala
11
star
36

ltsv4s

LTSV parser implementation in Scala
Scala
11
star
37

run-on-slack-deepl

A "run-on-slack" translator app powered by DeepL APIs
TypeScript
10
star
38

testgenerator

Scala test generator sbt plugin
Scala
10
star
39

new-relic-dashboard-in-slack

Tiny Bolt ⚡️ app demonstrating how to build Slack apps utilizing Slack's new features and New Relic APIs
JavaScript
10
star
40

kenall-for-slack

ケンオール API (kenall.jp) を Slack から使えるようにするアプリ
Python
9
star
41

bolt-starter-ts

TypeScript
9
star
42

apriori-algorithm

Apriori Algorithm Ruby implementation
Ruby
9
star
43

send-it-later-for-slack

Send It Later for Slack users
Python
8
star
44

jslack-maintenance-releases

Maintenance releases for the jSlack library
Java
8
star
45

deepl-document-translator-for-slack

Translate the document files in Slack
Python
8
star
46

hackernews4s

HackerNews API Client in Scala
Scala
8
star
47

bolt-aws-lambda-proof-of-concept

This repository was created in the aim of demonstrating the possibilities of proper FaaS (AWS Lambda, Google Cloud Functions etc) environment support by Bolt.
TypeScript
8
star
48

deepl-jvm

DeepL Kotlin/JavaVM Library
Kotlin
7
star
49

jp-holidays-for-slack

Slack app notifying national holidays in Japan
Python
7
star
50

spring-jersey-archetype

mvn archetype:generate -DarchetypeCatalog=http://seratch.github.com/mvn-repo/releases
Java
7
star
51

working-sql-in-scala

How to work with SQL queries in Scala - ScalikeJDBC, Slick StaticQuery and Anorm.
Scala
7
star
52

python-slack-scim

slack-scim - Slack SCIM API Client
Python
7
star
53

send-to-notion-in-slack-oss

Send to Notion in Slack (Simplified OSS Edition)
Python
7
star
54

oauth-server-example

Just an OAuth 1.0a server example in Java
Java
7
star
55

slack-next-generation-platform-tutorials

Complete project examples for https://dev.to/seratch/series/21161
TypeScript
6
star
56

taskun

A simple crond thread on the JVM
Java
6
star
57

slack-cli-gh-actions-demo

Demonstrating Slack CLI Deployment Using GitHub Actions
TypeScript
6
star
58

bolt-kotlin-on-aws-lambda

Building Bolt Java apps on AWS Lambda
Kotlin
6
star
59

scalatra-thymeleaf-support

Scalatra Thymeleaf Support
Scala
6
star
60

dallish

An extended Dalli for memcached 1.4.x
Ruby
6
star
61

slack-new-emoji-notification

New Slack Emoji Notifications Built with Slack's Automation Platform
TypeScript
6
star
62

scaruby

Scala API in Ruby
Ruby
5
star
63

memcachedweaver

Caching methods result on memcached with AOP
Java
5
star
64

xsbt-scalag-plugin

Scala code/resource Generator Plugin for xsbt
Scala
5
star
65

sqlite3-foreigner

foreigner extension for SQLite3 users
Ruby
5
star
66

spring-boot-swagger-demo

Spring Boot example to demonstrate how to integrate Swagger 2.0 and swagger-codegen
Java
5
star
67

deno-daily-notification-workflow

Slack app demonstrating how to build a daily scheduled message notification
TypeScript
5
star
68

gyotaku

Saving complete web pages by using Selenium Web Driver
Scala
5
star
69

bolt-js-aws-lambda

Bolt for JavaScript: AWS Lambda Receiver prototype
TypeScript
5
star
70

slack-mention-reminder

"Mention Reminder" is a custom Slack app that allows you to set up reminders simply by mentioning its bot
TypeScript
5
star
71

signedrequest4j

A Java library supporting OAuth 1.0 signing and verifying
Java
4
star
72

cloudflare-ai-translator-in-slack

Swift demonstration of how to utilize Cloudflare Workers AI within Slack's workflows
TypeScript
4
star
73

redmine-reverse-scaffold

Rerverse scaffold demo from Redmine database schema
Scala
4
star
74

apidays-workshop-2020

Apidays: Slack app workshop
Python
4
star
75

reactive-streams-jdbc

WIP: A sample to show how to work with RDBMS in the Reactive Streams way
Scala
4
star
76

apache-module-samples

Learning Apache 2.4 module development
C
4
star
77

seratch-slack-app-toolkit

A toolkit to build Slack Apps in TypeScript
TypeScript
4
star
78

play-2.5-example

[scalikejdbc-users-group:526]
Scala
4
star
79

kansai-summit-handson

Scala Kansai Summit 2015 【ハンズオン】Skinny Framework 2.0 で試すお手軽 Scala Web アプリ開発
Scala
4
star
80

long-lasting-scala.g8

An sbt project template for long lasting OSS maintainers
Scala
4
star
81

ninja-coffee-example

CoffeeScript, wro4j, WebJars and Ninja Framework
Java
3
star
82

jslack-kotlin-examples

A collection of Slack API examples in Kotlin
Kotlin
3
star
83

scala3-slack-socket-mode-app

Slack Socket Mode App in Scala 3
Scala
3
star
84

deno-slack-data-mapper-starter

deno-slack-data-mapper project template
TypeScript
3
star
85

slack-daily-standup-ja

デイリースクラム(Slack スタンダードワークフロー)
TypeScript
3
star
86

slack-standard-workflow-collection

Collection of Slack's "standard" workflow templates
TypeScript
3
star
87

skinny-engine-example

Skinny Framework 2 has its own engine instead of Scalatra.
Scala
3
star
88

scalikejdbc-play-plugin

DEPRECATED: Moved to https://github.com/scalikejdbc/scalikejdbc-play-support
Scala
3
star
89

new-relic-dashboard-in-slack-kotlin

Tiny Lightning ⚡️ app demonstrating how to build Slack apps utilizing Slack's new features and New Relic APIs
Kotlin
3
star
90

slack-edge-app-template

Slack app project template demonstrating how to manage your slack-edge app using Slack CLI
TypeScript
3
star
91

rpscala-scalatra-example

#rpscala 72 Scalatra Example App
Scala
2
star
92

deno-slack-source-file-resolver

Automatically resolve functions' source_file for Slack's next-generation platform apps
TypeScript
2
star
93

my-tour-of-go

https://tour.golang.org/
Go
2
star
94

slack-remote-functions-on-cloudflare

Build a remote function for Slack's automation platform on Cloudflare Workers
TypeScript
2
star
95

bootstrap-downloader

curl -L http://git.io/bootstrap-downloader | sh
JavaScript
2
star
96

deno-editable-form-submissions

Slack automation platform app demonstrating how to build a workflow that allows a submitter to edit or delete their channel message
TypeScript
2
star
97

go-slack-sdk-experimental

WIP: Experimental Slack SDK in Go
Go
2
star
98

scalatra-with-jsp

A Scalatra demo app which works with legacy jsp files.
Scala
2
star
99

hash-ninja

Hash operations toolkit for Ruby Ninja
Ruby
2
star
100

scalatra-openid-provider-support

Scalatra OpenID Provider Support
Scala
2
star