@zio.dev/zio-aws 5.17.29-5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/artifacts.md +342 -0
- package/aspects.md +45 -0
- package/changelog.md +66 -0
- package/configuration.md +98 -0
- package/examples.md +118 -0
- package/getting-started.md +44 -0
- package/http.md +152 -0
- package/index.md +9 -0
- package/migration_guide.md +223 -0
- package/package.json +6 -0
- package/sidebars.js +15 -0
- package/wrapper.md +153 -0
package/wrapper.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: wrappers
|
|
3
|
+
title: Wrappers
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Client wrappers
|
|
7
|
+
|
|
8
|
+
### Service modules
|
|
9
|
+
For each AWS Service the library defines a _ZIO service_ with wrapper functions for all the _operations_, a `live`
|
|
10
|
+
implementation calling the Java SDK and a `mock` implementation using [zio-mock](https://github.com/zio/zio-mock).
|
|
11
|
+
|
|
12
|
+
The live implementation depends on a core _AWS configuration layer_:
|
|
13
|
+
|
|
14
|
+
```scala
|
|
15
|
+
val live: ZLayer[AwsConfig, Throwable, Ec2]
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The `AwsConfig` layer defines how each service's async Java client gets configured, including the http client which is
|
|
19
|
+
provided by another layer `AwsConfig` is depending on.
|
|
20
|
+
|
|
21
|
+
Each module has accessor functions for _all operations_ of the given service.
|
|
22
|
+
|
|
23
|
+
### Operations
|
|
24
|
+
|
|
25
|
+
For simple request-response operations the library generates a very light wrapper:
|
|
26
|
+
|
|
27
|
+
```scala
|
|
28
|
+
def deleteVolume(request: DeleteVolumeRequest): ZIO[Ec2, AwsError, DeleteVolumeResponse.ReadOnly]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
For operations where either the input or the output or both are _byte streams_, a `ZStream` wrapper is generated:
|
|
32
|
+
|
|
33
|
+
```scala
|
|
34
|
+
def getObject(request: GetObjectRequest): ZIO[S3, AwsError, StreamingOutputResult[Any, GetObjectResponse.ReadOnly, Byte]]
|
|
35
|
+
def putObject(request: PutObjectRequest, body: ZStream[Any, AwsError, Byte]): ZIO[S3, AwsError, PutObjectResponse.ReadOnly]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
where the output is a stream packed together with additional response data:
|
|
39
|
+
|
|
40
|
+
```scala
|
|
41
|
+
case class StreamingOutputResult[R, Response, Item](
|
|
42
|
+
response: Response,
|
|
43
|
+
output: ZStream[R, AwsError, Item]
|
|
44
|
+
)
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For operations with _event streams_ a `ZStream` of a model type gets generated:
|
|
48
|
+
|
|
49
|
+
```scala
|
|
50
|
+
def startStreamTranscription(request: StartStreamTranscriptionRequest, input: ZStream[Any, AwsError, AudioStream]): ZStream[TranscribeStreaming, AwsError, TranscriptEvent.ReadOnly]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
And for all operations that supports _pagination_, streaming wrappers gets generated:
|
|
54
|
+
|
|
55
|
+
```scala
|
|
56
|
+
def scan(request: ScanRequest): ZStream[DynamoDb, AwsError, Map[AttributeName, AttributeValue.ReadOnly]]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Note that for event streaming or paginating operations returning a `ZStream` the actual AWS call happens when the stream gets pulled.
|
|
60
|
+
|
|
61
|
+
For use cases when calling the _paginating_ interface directly is necessary - for example when forwarding paginated results through a HTTP API, the library generates non-streaming wrappers as well for these methods.
|
|
62
|
+
|
|
63
|
+
For example the DynamoDB `scan` method's non-streaming variant is defined as:
|
|
64
|
+
|
|
65
|
+
```scala
|
|
66
|
+
def scanPaginated(request: ScanRequest): ZIO[DynamoDb, ScanResponse.ReadOnly]
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Model wrappers
|
|
70
|
+
For each model type a set of wrappers are generated, providing the following functionality:
|
|
71
|
+
|
|
72
|
+
- Case classes with default parameter values instead of the _builder pattern_
|
|
73
|
+
- [zio-prelude's newtype wrappers](https://zio.github.io/zio-prelude/docs/newtypes/) for primitive types
|
|
74
|
+
- Automatic conversion to Scala collection types
|
|
75
|
+
- ADTs instead of the Java enums
|
|
76
|
+
- ZIO getter functions to "get or fail" the optional model fields
|
|
77
|
+
- Using zio-prelude's `Optional` type to eliminate boilerplate when constructing models with many optional fields
|
|
78
|
+
|
|
79
|
+
The following example from the `zio-aws-elasticsearch` library shows how the generated case classes look like, to be used as input for the service operations:
|
|
80
|
+
|
|
81
|
+
```scala
|
|
82
|
+
case class DescribePackagesFilter(name: Optional[DescribePackagesFilterName] = Optional.Absent,
|
|
83
|
+
value: Optional[Iterable[primitives.DescribePackagesFilterValue]] = Optional.Absent) {
|
|
84
|
+
def buildAwsValue(): software.amazon.awssdk.services.elasticsearch.model.DescribePackagesFilter = {
|
|
85
|
+
import DescribePackagesFilter.zioAwsBuilderHelper.BuilderOps
|
|
86
|
+
software.amazon.awssdk.services.elasticsearch.model.DescribePackagesFilter
|
|
87
|
+
.builder()
|
|
88
|
+
.optionallyWith(name.map(value => value.unwrap))(_.name)
|
|
89
|
+
.optionallyWith(value.map(value => value.map { item => item: java.lang.String }.asJava))(_.value)
|
|
90
|
+
.build()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
def asReadOnly: DescribePackagesFilter.ReadOnly = DescribePackagesFilter.wrap(buildAwsValue())
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
When processing the _results_ of the operations (either directly or though the `ZStream` wrappers), the AWS Java model types are wrapped
|
|
98
|
+
by a _read-only wrapper interface_. The following example shows one from the `transcribe` module:
|
|
99
|
+
|
|
100
|
+
```scala
|
|
101
|
+
object CreateMedicalVocabularyResponse {
|
|
102
|
+
private lazy val zioAwsBuilderHelper: BuilderHelper[software.amazon.awssdk.services.transcribe.model.CreateMedicalVocabularyResponse] = BuilderHelper.apply
|
|
103
|
+
|
|
104
|
+
trait ReadOnly {
|
|
105
|
+
def editable: CreateMedicalVocabularyResponse = CreateMedicalVocabularyResponse(vocabularyNameValue.map(value => value), languageCodeValue.map(value => value), vocabularyStateValue.map(value => value), lastModifiedTimeValue.map(value => value), failureReasonValue.map(value => value))
|
|
106
|
+
def vocabularyName: Optional[VocabularyName]
|
|
107
|
+
def languageCode: Optional[LanguageCode]
|
|
108
|
+
def vocabularyState: Optional[VocabularyState]
|
|
109
|
+
def lastModifiedTime: Optional[DateTime]
|
|
110
|
+
def failureReason: Optional[FailureReason]
|
|
111
|
+
def getVocabularyName: ZIO[Any, AwsError, VocabularyName] = AwsError.unwrapOptionField("vocabularyName", vocabularyNameValue)
|
|
112
|
+
def getLanguageCode: ZIO[Any, AwsError, LanguageCode] = AwsError.unwrapOptionField("languageCode", languageCodeValue)
|
|
113
|
+
def getVocabularyState: ZIO[Any, AwsError, VocabularyState] = AwsError.unwrapOptionField("vocabularyState", vocabularyStateValue)
|
|
114
|
+
def getLastModifiedTime: ZIO[Any, AwsError, DateTime] = AwsError.unwrapOptionField("lastModifiedTime", lastModifiedTimeValue)
|
|
115
|
+
def getFailureReason: ZIO[Any, AwsError, FailureReason] = AwsError.unwrapOptionField("failureReason", failureReasonValue)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private class Wrapper(impl: software.amazon.awssdk.services.transcribe.model.CreateMedicalVocabularyResponse) extends CreateMedicalVocabularyResponse.ReadOnly {
|
|
119
|
+
// ... implements the ReadOnly interface by querying the underlying Java object
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
def wrap(impl: software.amazon.awssdk.services.transcribe.model.CreateMedicalVocabularyResponse): ReadOnly = new Wrapper(impl)
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
As a large part of the models in the AWS SDK are defined as _optional_, the generated wrapper also contains ZIO accessor functions,
|
|
127
|
+
which lift the option value to make it more comfortable to chain the AWS operations.
|
|
128
|
+
|
|
129
|
+
### Mocks
|
|
130
|
+
Each module also contains generated [_ZIO Test mocks_](https://github.com/zio/zio-mock) for the given service.
|
|
131
|
+
|
|
132
|
+
The following example shows how to use them with the `zio-aws-athena` library:
|
|
133
|
+
|
|
134
|
+
```scala
|
|
135
|
+
val athena = AthenaMock.StartQueryExecution(
|
|
136
|
+
hasField(
|
|
137
|
+
"queryString",
|
|
138
|
+
(startQueryExecutionRequest: StartQueryExecutionRequest) =>
|
|
139
|
+
startQueryExecutionRequest.queryString,
|
|
140
|
+
equalTo(givenQuery)
|
|
141
|
+
),
|
|
142
|
+
value(
|
|
143
|
+
StartQueryExecutionResponse.wrap(
|
|
144
|
+
software.amazon.awssdk.services.athena.model.StartQueryExecutionResponse
|
|
145
|
+
.builder()
|
|
146
|
+
.queryExecutionId(executionId)
|
|
147
|
+
build()
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
codeUsingAthena.provide(athena)
|
|
153
|
+
```
|