This Scala library wraps selected parts of the AWS SDK for Java 2.x to offer simpler, scala-idiomatic API.
- IAM
- DynamoDB
- ApiGateway
- SQS
- Lambda
- S3
- SecretsManager
- STS
- KMS
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
- Scala >= 3.6.3
- Scala toolkit 0.7.0
- org.slf4j slf4j-nop 2.0.17
- software.amazon.awssdk bom 2.31.6 | iam 2.31.6 | sts 2.31.6 | sso 2.31.6 | ssooidc 2.31.6 | dynamodb 2.31.6 | sqs 2.31.6 | secretsmanager 2.31.6 | kms 2.31.6 | s3 2.31.6 | lambda 2.31.6 | apigateway 2.31.6 | apigatewayv2 2.31.6 | url-connection-client 2.31.6
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))
}
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)
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)
├── .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