https://github.com/encalmo/scala-aws-client
This Scala library wraps selected parts of the AWS SDK for Java 2.x to offer simpler, scala-idiomatic API.
https://github.com/encalmo/scala-aws-client
aws-client scala scala3
Last synced: about 2 months ago
JSON representation
This Scala library wraps selected parts of the AWS SDK for Java 2.x to offer simpler, scala-idiomatic API.
- Host: GitHub
- URL: https://github.com/encalmo/scala-aws-client
- Owner: encalmo
- License: mit
- Created: 2025-03-03T20:02:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-18T19:01:15.000Z (about 1 year ago)
- Last Synced: 2025-03-18T20:22:33.735Z (about 1 year ago)
- Topics: aws-client, scala, scala3
- Language: Scala
- Homepage: https://encalmo.github.io/scala-aws-client/
- Size: 148 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
  
# scala-aws-client
This Scala library wraps selected parts of the [AWS SDK for Java 2.x](https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/home.html) to offer simpler, scala-idiomatic API.
## Table of contents
- [Services](#services)
- [Usage](#usage)
- [Dependencies](#dependencies)
- [Working with DynamoDB](#working-with-dynamodb)
- [Using AwsDynamoDbApi](#using-awsdynamodbapi)
- [Using DynamoDbTable trait](#using-dynamodbtable-trait)
- [Using DynamoDbTableWithSortKey trait](#using-dynamodbtablewithsortkey-trait)
## Services
- IAM
- DynamoDB
- ApiGateway
- SQS
- Lambda
- S3
- SecretsManager
- STS
- KMS
## Usage
Use with SBT
libraryDependencies += "org.encalmo" %% "scala-aws-client" % "0.9.8"
or with SCALA-CLI
//> using dep org.encalmo::scala-aws-client:0.9.8
## Dependencies
- [Scala](https://www.scala-lang.org) >= 3.6.3
- [Scala **toolkit** 0.7.0](https://github.com/scala/toolkit)
- org.slf4j [**slf4j-nop** 2.0.17](https://central.sonatype.com/artifact/org.slf4j/slf4j-nop)
- software.amazon.awssdk [**bom** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/bom) | [**iam** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/iam) | [**sts** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/sts) | [**sso** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/sso) | [**ssooidc** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/ssooidc) | [**dynamodb** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/dynamodb) | [**sqs** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/sqs) | [**secretsmanager** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/secretsmanager) | [**kms** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/kms) | [**s3** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/s3) | [**lambda** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/lambda) | [**apigateway** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/apigateway) | [**apigatewayv2** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/apigatewayv2) | [**url-connection-client** 2.31.6](https://central.sonatype.com/artifact/software.amazon.awssdk/url-connection-client)
## Working with DynamoDB
### Using AwsDynamoDbApi
```scala
import org.encalmo.aws.AwsClient
import org.encalmo.aws.AwsDynamoDbApi.*
import org.encalmo.aws.AwsDynamoDbApi.given
import org.encalmo.models.{CUID2, Amount}
val id = CUID2.randomCUID2()
AwsClient.maybe {
putItemInTable(
tableName = "items",
item = DynamoDbItem(
"item_id" -> id,
"status" -> "fine",
"price" -> 12345,
"is_for_sale" -> true
)
)
}
val item3 = AwsClient.optionally {
getItemFromTable("items", ("item_id" -> id))
}
```
### Using DynamoDbTable trait
```scala
import org.encalmo.aws.DynamoDbTable
import org.encalmo.aws.AwsDynamoDbApi.{*,given}
import org.encalmo.models.{CUID2, Amount}
given DynamoDbEnvironment = DefaultDynamoDbEnvironment
given ErrorContext = DefaultErrorContext
case class Item(
item_id: CUID2,
price: Amount,
`is-for-sale`: Boolean,
description: Option[String] = None
)
object Items extends DynamoDbTable[CUID2]("item_id") {
override inline def baseTableName: String = "items"
}
val id = CUID2.randomCUID2()
val item = Item(
item_id = id,
price = Amount(1234),
is_for_sale = false
)
Items.setItem(item)
val item2 = Items.getItemAsClass[Item](id)
assert(item2.isDefined)
Items.getItem(id)
Items.setItemProperties(id, "is_for_sale" -> true, "price" -> Amount(1234))
Items.setItemProperties(id, "description" -> "some old crap")
Items.getItem(id)
Items.removeItem(id)
```
### Using DynamoDbTableWithSortKey trait
```scala
import org.encalmo.aws.DynamoDbTable
import org.encalmo.aws.AwsDynamoDbApi.{*,given}
import org.encalmo.models.{CUID2, Amount}
object OrdersTable extends DynamoDbTableWithSortKey[String, Long]("order_id", "createdAt") {
override inline def baseTableName: String = "orders"
}
given DynamoDbEnvironment = DefaultDynamoDbEnvironment
given ErrorContext = DefaultErrorContext
val id = CUID2.randomCUID2()
val createdAt = Instant.now().getEpochSecond()
assert(OrdersTable.getItemOrError(id, createdAt).isLeft)
OrdersTable.setItemProperties(id, createdAt, "status" -> "submitted")
assert(OrdersTable.getItemOrError(id, createdAt).isRight)
OrdersTable.removeItemProperty(id, createdAt, "status")
assert(OrdersTable.getItemOrError(id, createdAt).isRight)
OrdersTable.removeItem(id, createdAt)
assert(OrdersTable.getItemOrError(id, createdAt).isLeft)
```
## Project content
```
├── .github
│ └── workflows
│ ├── pages.yaml
│ ├── release.yaml
│ └── test.yaml
│
├── .gitignore
├── .scalafix.conf
├── .scalafmt.conf
├── AwsApiGatewayApi.scala
├── AwsApiGatewayV2Api.scala
├── AwsClient.scala
├── AwsClient.test.scala
├── AwsClientStatefulStub.scala
├── AwsClientStatefulStub.test.scala
├── AwsClientStatelessStub.scala
├── AwsClientStatelessStub.test.scala
├── AwsDynamoDbApi.scala
├── AwsDynamoDbApi.test.scala
├── AwsIamApi.scala
├── AwsKmsApi.scala
├── AwsKmsApi.test.scala
├── AwsLambdaApi.scala
├── AwsLambdaApi.test.scala
├── AwsS3Api.scala
├── AwsSecretsManagerApi.scala
├── AwsSqsApi.scala
├── AwsStsApi.scala
├── AwsStsApi.test.scala
├── DynamoDbEnvironment.scala
├── DynamoDbTable.scala
├── DynamoDbTable.test.scala
├── DynamoDbTableWithSortKey.scala
├── DynamoDbTableWithSortKey.test.scala
├── ErrorContext.scala
├── LICENSE
├── Macros.scala
├── Macros.test.scala
├── project.scala
├── README.md
├── test.sh
├── TestSuite.test.scala
└── Utils.scala
```