/
api_op_TransactWriteItems.go
314 lines (283 loc) · 12.1 KB
/
api_op_TransactWriteItems.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
// Code generated by smithy-go-codegen DO NOT EDIT.
package dynamodb
import (
"context"
"fmt"
awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
internalEndpointDiscovery "github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery"
"github.com/aws/smithy-go/middleware"
smithyhttp "github.com/aws/smithy-go/transport/http"
)
// TransactWriteItems is a synchronous write operation that groups up to 100 action
// requests. These actions can target items in different tables, but not in
// different Amazon Web Services accounts or Regions, and no two actions can target
// the same item. For example, you cannot both ConditionCheck and Update the same
// item. The aggregate size of the items in the transaction cannot exceed 4 MB. The
// actions are completed atomically so that either all of them succeed, or all of
// them fail. They are defined by the following objects:
//
// * Put — Initiates a
// PutItem operation to write a new item. This structure specifies the primary key
// of the item to be written, the name of the table to write it in, an optional
// condition expression that must be satisfied for the write to succeed, a list of
// the item's attributes, and a field indicating whether to retrieve the item's
// attributes if the condition is not met.
//
// * Update — Initiates an UpdateItem
// operation to update an existing item. This structure specifies the primary key
// of the item to be updated, the name of the table where it resides, an optional
// condition expression that must be satisfied for the update to succeed, an
// expression that defines one or more attributes to be updated, and a field
// indicating whether to retrieve the item's attributes if the condition is not
// met.
//
// * Delete — Initiates a DeleteItem operation to delete an existing item.
// This structure specifies the primary key of the item to be deleted, the name of
// the table where it resides, an optional condition expression that must be
// satisfied for the deletion to succeed, and a field indicating whether to
// retrieve the item's attributes if the condition is not met.
//
// * ConditionCheck —
// Applies a condition to an item that is not being modified by the transaction.
// This structure specifies the primary key of the item to be checked, the name of
// the table where it resides, a condition expression that must be satisfied for
// the transaction to succeed, and a field indicating whether to retrieve the
// item's attributes if the condition is not met.
//
// DynamoDB rejects the entire
// TransactWriteItems request if any of the following is true:
//
// * A condition in
// one of the condition expressions is not met.
//
// * An ongoing operation is in the
// process of updating the same item.
//
// * There is insufficient provisioned capacity
// for the transaction to be completed.
//
// * An item size becomes too large (bigger
// than 400 KB), a local secondary index (LSI) becomes too large, or a similar
// validation error occurs because of changes made by the transaction.
//
// * The
// aggregate size of the items in the transaction exceeds 4 MB.
//
// * There is a user
// error, such as an invalid data format.
func (c *Client) TransactWriteItems(ctx context.Context, params *TransactWriteItemsInput, optFns ...func(*Options)) (*TransactWriteItemsOutput, error) {
if params == nil {
params = &TransactWriteItemsInput{}
}
result, metadata, err := c.invokeOperation(ctx, "TransactWriteItems", params, optFns, c.addOperationTransactWriteItemsMiddlewares)
if err != nil {
return nil, err
}
out := result.(*TransactWriteItemsOutput)
out.ResultMetadata = metadata
return out, nil
}
type TransactWriteItemsInput struct {
// An ordered array of up to 100 TransactWriteItem objects, each of which contains
// a ConditionCheck, Put, Update, or Delete object. These can operate on items in
// different tables, but the tables must reside in the same Amazon Web Services
// account and Region, and no two of them can operate on the same item.
//
// This member is required.
TransactItems []types.TransactWriteItem
// Providing a ClientRequestToken makes the call to TransactWriteItems idempotent,
// meaning that multiple identical calls have the same effect as one single call.
// Although multiple identical calls using the same client request token produce
// the same result on the server (no side effects), the responses to the calls
// might not be the same. If the ReturnConsumedCapacity parameter is set, then the
// initial TransactWriteItems call returns the amount of write capacity units
// consumed in making the changes. Subsequent TransactWriteItems calls with the
// same client token return the number of read capacity units consumed in reading
// the item. A client request token is valid for 10 minutes after the first request
// that uses it is completed. After 10 minutes, any request with the same client
// token is treated as a new request. Do not resubmit the same request with the
// same client token for more than 10 minutes, or the result might not be
// idempotent. If you submit a request with the same client token but a change in
// other parameters within the 10-minute idempotency window, DynamoDB returns an
// IdempotentParameterMismatch exception.
ClientRequestToken *string
// Determines the level of detail about either provisioned or on-demand throughput
// consumption that is returned in the response:
//
// * INDEXES - The response includes
// the aggregate ConsumedCapacity for the operation, together with ConsumedCapacity
// for each table and secondary index that was accessed. Note that some operations,
// such as GetItem and BatchGetItem, do not access any indexes at all. In these
// cases, specifying INDEXES will only return ConsumedCapacity information for
// table(s).
//
// * TOTAL - The response includes only the aggregate ConsumedCapacity
// for the operation.
//
// * NONE - No ConsumedCapacity details are included in the
// response.
ReturnConsumedCapacity types.ReturnConsumedCapacity
// Determines whether item collection metrics are returned. If set to SIZE, the
// response includes statistics about item collections (if any), that were modified
// during the operation and are returned in the response. If set to NONE (the
// default), no statistics are returned.
ReturnItemCollectionMetrics types.ReturnItemCollectionMetrics
noSmithyDocumentSerde
}
type TransactWriteItemsOutput struct {
// The capacity units consumed by the entire TransactWriteItems operation. The
// values of the list are ordered according to the ordering of the TransactItems
// request parameter.
ConsumedCapacity []types.ConsumedCapacity
// A list of tables that were processed by TransactWriteItems and, for each table,
// information about any item collections that were affected by individual
// UpdateItem, PutItem, or DeleteItem operations.
ItemCollectionMetrics map[string][]types.ItemCollectionMetrics
// Metadata pertaining to the operation's result.
ResultMetadata middleware.Metadata
noSmithyDocumentSerde
}
func (c *Client) addOperationTransactWriteItemsMiddlewares(stack *middleware.Stack, options Options) (err error) {
err = stack.Serialize.Add(&awsAwsjson10_serializeOpTransactWriteItems{}, middleware.After)
if err != nil {
return err
}
err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpTransactWriteItems{}, middleware.After)
if err != nil {
return err
}
if err = addSetLoggerMiddleware(stack, options); err != nil {
return err
}
if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
return err
}
if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
return err
}
if err = addResolveEndpointMiddleware(stack, options); err != nil {
return err
}
if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
return err
}
if err = addRetryMiddlewares(stack, options); err != nil {
return err
}
if err = addHTTPSignerV4Middleware(stack, options); err != nil {
return err
}
if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
return err
}
if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
return err
}
if err = addClientUserAgent(stack); err != nil {
return err
}
if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
return err
}
if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
return err
}
if err = addOpTransactWriteItemsDiscoverEndpointMiddleware(stack, options, c); err != nil {
return err
}
if err = addIdempotencyToken_opTransactWriteItemsMiddleware(stack, options); err != nil {
return err
}
if err = addOpTransactWriteItemsValidationMiddleware(stack); err != nil {
return err
}
if err = stack.Initialize.Add(newServiceMetadataMiddleware_opTransactWriteItems(options.Region), middleware.Before); err != nil {
return err
}
if err = addRequestIDRetrieverMiddleware(stack); err != nil {
return err
}
if err = addResponseErrorMiddleware(stack); err != nil {
return err
}
if err = addValidateResponseChecksum(stack, options); err != nil {
return err
}
if err = addAcceptEncodingGzip(stack, options); err != nil {
return err
}
if err = addRequestResponseLogging(stack, options); err != nil {
return err
}
return nil
}
func addOpTransactWriteItemsDiscoverEndpointMiddleware(stack *middleware.Stack, o Options, c *Client) error {
return stack.Serialize.Insert(&internalEndpointDiscovery.DiscoverEndpoint{
Options: []func(*internalEndpointDiscovery.DiscoverEndpointOptions){
func(opt *internalEndpointDiscovery.DiscoverEndpointOptions) {
opt.DisableHTTPS = o.EndpointOptions.DisableHTTPS
opt.Logger = o.Logger
},
},
DiscoverOperation: c.fetchOpTransactWriteItemsDiscoverEndpoint,
EndpointDiscoveryEnableState: o.EndpointDiscovery.EnableEndpointDiscovery,
EndpointDiscoveryRequired: false,
}, "ResolveEndpoint", middleware.After)
}
func (c *Client) fetchOpTransactWriteItemsDiscoverEndpoint(ctx context.Context, input interface{}, optFns ...func(*internalEndpointDiscovery.DiscoverEndpointOptions)) (internalEndpointDiscovery.WeightedAddress, error) {
in, ok := input.(*TransactWriteItemsInput)
if !ok {
return internalEndpointDiscovery.WeightedAddress{}, fmt.Errorf("unknown input type %T", input)
}
_ = in
identifierMap := make(map[string]string, 0)
key := fmt.Sprintf("DynamoDB.%v", identifierMap)
if v, ok := c.endpointCache.Get(key); ok {
return v, nil
}
discoveryOperationInput := &DescribeEndpointsInput{}
opt := internalEndpointDiscovery.DiscoverEndpointOptions{}
for _, fn := range optFns {
fn(&opt)
}
go c.handleEndpointDiscoveryFromService(ctx, discoveryOperationInput, key, opt)
return internalEndpointDiscovery.WeightedAddress{}, nil
}
type idempotencyToken_initializeOpTransactWriteItems struct {
tokenProvider IdempotencyTokenProvider
}
func (*idempotencyToken_initializeOpTransactWriteItems) ID() string {
return "OperationIdempotencyTokenAutoFill"
}
func (m *idempotencyToken_initializeOpTransactWriteItems) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
out middleware.InitializeOutput, metadata middleware.Metadata, err error,
) {
if m.tokenProvider == nil {
return next.HandleInitialize(ctx, in)
}
input, ok := in.Parameters.(*TransactWriteItemsInput)
if !ok {
return out, metadata, fmt.Errorf("expected middleware input to be of type *TransactWriteItemsInput ")
}
if input.ClientRequestToken == nil {
t, err := m.tokenProvider.GetIdempotencyToken()
if err != nil {
return out, metadata, err
}
input.ClientRequestToken = &t
}
return next.HandleInitialize(ctx, in)
}
func addIdempotencyToken_opTransactWriteItemsMiddleware(stack *middleware.Stack, cfg Options) error {
return stack.Initialize.Add(&idempotencyToken_initializeOpTransactWriteItems{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
}
func newServiceMetadataMiddleware_opTransactWriteItems(region string) *awsmiddleware.RegisterServiceMetadata {
return &awsmiddleware.RegisterServiceMetadata{
Region: region,
ServiceID: ServiceID,
SigningName: "dynamodb",
OperationName: "TransactWriteItems",
}
}