Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zio/zio-aws
Low level ZIO interface for the full AWS
https://github.com/zio/zio-aws
aws scala zio
Last synced: 7 days ago
JSON representation
Low level ZIO interface for the full AWS
- Host: GitHub
- URL: https://github.com/zio/zio-aws
- Owner: zio
- License: apache-2.0
- Created: 2020-08-06T22:45:01.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-12-09T03:38:36.000Z (18 days ago)
- Last Synced: 2024-12-13T18:09:33.064Z (14 days ago)
- Topics: aws, scala, zio
- Language: Scala
- Homepage: https://zio.dev/zio-aws
- Size: 5.15 MB
- Stars: 140
- Watchers: 8
- Forks: 34
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[//]: # (This file was autogenerated using `zio-sbt-website` plugin via `sbt generateReadme` command.)
[//]: # (So please do not edit it manually. Instead, change "docs/index.md" file or sbt setting keys)
[//]: # (e.g. "readmeDocumentation" and "readmeSupport".)# ZIO AWS
[ZIO AWS](https://zio.dev/zio-aws) is AWS wrapper for [ZIO](https://zio.dev) for _all_ AWS services using the AWS Java SDK v2.
[![Production Ready](https://img.shields.io/badge/Project%20Stage-Production%20Ready-brightgreen.svg)](https://github.com/zio/zio/wiki/Project-Stages) ![CI Badge](https://github.com/zio/zio-aws/workflows/CI/badge.svg) [![Sonatype Releases](https://img.shields.io/nexus/r/https/oss.sonatype.org/dev.zio/zio-aws-core_2.13.svg?label=Sonatype%20Release)](https://oss.sonatype.org/content/repositories/releases/dev/zio/zio-aws-core_2.13/) [![Sonatype Snapshots](https://img.shields.io/nexus/s/https/oss.sonatype.org/dev.zio/zio-aws-core_2.13.svg?label=Sonatype%20Snapshot)](https://oss.sonatype.org/content/repositories/snapshots/dev/zio/zio-aws-core_2.13/) [![javadoc](https://javadoc.io/badge2/dev.zio/zio-aws-docs_2.13/javadoc.svg)](https://javadoc.io/doc/dev.zio/zio-aws-docs_2.13) [![ZIO AWS](https://img.shields.io/github/stars/zio/zio-aws?style=social)](https://github.com/zio/zio-aws)
## Introduction
The goal is to have access to all AWS functionality for cases when only a simple, direct access is needed from a ZIO application, or to be used as a building block for higher level wrappers around specific services.
Key features of ZIO AWS:
- Common configuration layer
- ZIO module layer per AWS service
- Wrapper for all operations on all services
- HTTP service implementations for functional Scala HTTP libraries, injected through ZIO’s module system
- ZStream wrapper around paginated operations
- Service-specific extra configuration
- More idiomatic Scala request and response types wrapping the Java classes## Installation
There are tones of artifacts [published](docs/artifacts.md) for each AWS service. We can pick whichever services we need.
## Example
The following example uses the _ElasticBeanstalk_ and _EC2_ APIs:
> **Note**
>
> See the [artifacts](docs/artifacts.md) page for the latest release.```scala
libraryDependencies += "dev.zio" %% "zio-aws-core" % ""
libraryDependencies += "dev.zio" %% "zio-aws-ec2" % ""
libraryDependencies += "dev.zio" %% "zio-aws-elasticbeanstalk" % ""
libraryDependencies += "dev.zio" %% "zio-aws-netty" % ""
```And here is the example code:
```scala
import zio.aws.core.AwsError
import zio.aws.core.config.AwsConfig
import zio.aws.ec2.Ec2
import zio.aws.ec2.model._
import zio.aws.ec2.model.primitives._
import zio.aws.elasticbeanstalk.ElasticBeanstalk
import zio.aws.elasticbeanstalk.model._
import zio.aws.elasticbeanstalk.model.primitives._
import zio.aws.netty.NettyHttpClient
import zio._
import zio.stream._object ZIOAWSExample extends ZIOAppDefault {
val program: ZIO[Ec2 & ElasticBeanstalk, AwsError, Unit] =
for {
appsResult <- ElasticBeanstalk.describeApplications(
DescribeApplicationsRequest(applicationNames = Some(List(ApplicationName("my-service"))))
)
app <- appsResult.getApplications.map(_.headOption)
_ <- app match {
case Some(appDescription) =>
for {
applicationName <- appDescription.getApplicationName
_ <- Console
.printLine(
s"Got application description for $applicationName"
)
.ignoreenvStream = ElasticBeanstalk.describeEnvironments(
DescribeEnvironmentsRequest(applicationName =
Some(applicationName)
)
)_ <- envStream.run(ZSink.foreach { env =>
env.getEnvironmentName.flatMap { environmentName =>
(for {
environmentId <- env.getEnvironmentId
_ <- Console
.printLine(
s"Getting the EB resources of $environmentName"
)
.ignoreresourcesResult <-
ElasticBeanstalk.describeEnvironmentResources(
DescribeEnvironmentResourcesRequest(environmentId =
Some(environmentId)
)
)
resources <- resourcesResult.getEnvironmentResources
_ <- Console
.printLine(
s"Getting the EC2 instances in $environmentName"
)
.ignore
instances <- resources.getInstances
instanceIds <- ZIO.foreach(instances)(_.getId)
_ <- Console
.printLine(
s"Instance IDs are ${instanceIds.mkString(", ")}"
)
.ignorereservationsStream = Ec2.describeInstances(
DescribeInstancesRequest(instanceIds = Some(instanceIds.map(id => zio.aws.ec2.model.primitives.InstanceId(ResourceId.unwrap(id)))))
)
_ <- reservationsStream.run(ZSink.foreach { reservation =>
reservation.getInstances
.flatMap { instances =>
ZIO.foreach(instances) { instance =>
for {
id <- instance.getInstanceId
typ <- instance.getInstanceType
launchTime <- instance.getLaunchTime
_ <- Console.printLine(s" instance $id:").ignore
_ <- Console.printLine(s" type: $typ").ignore
_ <- Console
.printLine(
s" launched at: $launchTime"
)
.ignore
} yield ()
}
}
})
} yield ()).catchAll { error =>
Console
.printLineError(
s"Failed to get info for $environmentName: $error"
)
.ignore
}
}
})
} yield ()
case None =>
ZIO.unit
}
} yield ()override def run: URIO[ZIOAppArgs, ExitCode] = {
val httpClient = NettyHttpClient.default
val awsConfig = httpClient >>> AwsConfig.default
val aws = awsConfig >>> (Ec2.live ++ ElasticBeanstalk.live)program
.provideLayer(aws)
.either
.flatMap {
case Left(error) =>
Console.printLineError(s"AWS error: $error").ignore.as(ExitCode.failure)
case Right(_) =>
ZIO.unit.as(ExitCode.success)
}
}
}
```## Documentation
Learn more on the [ZIO AWS homepage](https://github.com/zio/zio-aws)!
## Contributing
For the general guidelines, see ZIO [contributor's guide](https://zio.dev/about/contributing).
## Code of Conduct
See the [Code of Conduct](https://zio.dev/about/code-of-conduct)
## Support
Come chat with us on [![Badge-Discord]][Link-Discord].
[Badge-Discord]: https://img.shields.io/discord/629491597070827530?logo=discord "chat on discord"
[Link-Discord]: https://discord.gg/2ccFBr4 "Discord"## License
[License](LICENSE)