https://github.com/maginepro/http4s-aws
Signed AWS API requests for http4s :lock:
https://github.com/maginepro/http4s-aws
aws http4s scala
Last synced: 11 months ago
JSON representation
Signed AWS API requests for http4s :lock:
- Host: GitHub
- URL: https://github.com/maginepro/http4s-aws
- Owner: maginepro
- License: apache-2.0
- Created: 2025-03-13T12:52:51.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-06-09T07:22:40.000Z (12 months ago)
- Last Synced: 2025-06-09T08:28:49.153Z (12 months ago)
- Topics: aws, http4s, scala
- Language: Scala
- Homepage:
- Size: 212 KB
- Stars: 5
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# :lock: http4s-aws
Provides [http4s](https://http4s.org) request authentication using [AWS Signature Version 4](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-signing.html) signing.
The library is inspired by [filosganga/http4s-aws](https://github.com/filosganga/http4s-aws) but with significant differences.
## Usage
You can add the following line to `build.sbt` to use the library.
```scala
libraryDependencies += "com.magine" %% "http4s-aws" % http4sAwsVersion
```
Make sure to replace `http4sAwsVersion` with a [release version](https://github.com/maginepro/http4s-aws/releases).
Replace `%%` with `%%%` if you are using [Scala.js](https://www.scala-js.org).
## Quick Example
Create a `CredentialsProvider` and use `AwsSigningClient` to wrap an existing client.
```scala
import cats.effect.IO
import cats.effect.IOApp
import com.magine.aws.Region
import com.magine.http4s.aws.AwsServiceName
import com.magine.http4s.aws.AwsSigningClient
import com.magine.http4s.aws.CredentialsProvider
import org.http4s.ember.client.EmberClientBuilder
import org.http4s.Request
object Main extends IOApp.Simple {
def run: IO[Unit] = {
val client =
for {
client <- EmberClientBuilder.default[IO].build
provider <- CredentialsProvider.default(client)
region = Region.EU_WEST_1
serviceName = AwsServiceName.Elasticsearch
signingClient = AwsSigningClient(provider, region, serviceName)(client)
} yield signingClient
val request: Request[IO] =
Request()
client.use(_.expect[Unit](request))
}
}
```
If pre-signing of requests is necessary, instead use `AwsPresigning`.
```scala
import cats.effect.IO
import cats.effect.IOApp
import com.magine.aws.Region
import com.magine.http4s.aws.AwsPresigning
import com.magine.http4s.aws.AwsServiceName
import com.magine.http4s.aws.CredentialsProvider
import org.http4s.ember.client.EmberClientBuilder
import org.http4s.Request
import scala.concurrent.duration._
object Main extends IOApp.Simple {
def run: IO[Unit] = {
val presigning =
for {
client <- EmberClientBuilder.default[IO].build
provider <- CredentialsProvider.default(client)
region = Region.EU_WEST_1
serviceName = AwsServiceName.S3
expiry = 5.minutes
presigning = AwsPresigning(provider, region, serviceName, expiry)
} yield presigning
val request: Request[IO] =
Request()
presigning
.use(_.presign(request))
.map(_.uri.renderString)
.flatMap(IO.println)
}
}
```