1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package dynamodb
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/aws-sdk-go-v2/service/dynamodb/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Creates a global table from an existing table. A global table creates a
15// replication relationship between two or more DynamoDB tables with the same table
16// name in the provided Regions. This operation only applies to Version 2017.11.29
17// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/globaltables.V1.html)
18// of global tables. If you want to add a new replica table to a global table, each
19// of the following conditions must be true:
20//
21// * The table must have the same
22// primary key as all of the other replicas.
23//
24// * The table must have the same name
25// as all of the other replicas.
26//
27// * The table must have DynamoDB Streams enabled,
28// with the stream containing both the new and the old images of the item.
29//
30// * None
31// of the replica tables in the global table can contain any data.
32//
33// If global
34// secondary indexes are specified, then the following conditions must also be
35// met:
36//
37// * The global secondary indexes must have the same name.
38//
39// * The global
40// secondary indexes must have the same hash key and sort key (if present).
41//
42// If
43// local secondary indexes are specified, then the following conditions must also
44// be met:
45//
46// * The local secondary indexes must have the same name.
47//
48// * The local
49// secondary indexes must have the same hash key and sort key (if present).
50//
51// Write
52// capacity settings should be set consistently across your replica tables and
53// secondary indexes. DynamoDB strongly recommends enabling auto scaling to manage
54// the write capacity settings for all of your global tables replicas and indexes.
55// If you prefer to manage write capacity settings manually, you should provision
56// equal replicated write capacity units to your replica tables. You should also
57// provision equal replicated write capacity units to matching secondary indexes
58// across your global table.
59func (c *Client) CreateGlobalTable(ctx context.Context, params *CreateGlobalTableInput, optFns ...func(*Options)) (*CreateGlobalTableOutput, error) {
60	if params == nil {
61		params = &CreateGlobalTableInput{}
62	}
63
64	result, metadata, err := c.invokeOperation(ctx, "CreateGlobalTable", params, optFns, addOperationCreateGlobalTableMiddlewares)
65	if err != nil {
66		return nil, err
67	}
68
69	out := result.(*CreateGlobalTableOutput)
70	out.ResultMetadata = metadata
71	return out, nil
72}
73
74type CreateGlobalTableInput struct {
75
76	// The global table name.
77	//
78	// This member is required.
79	GlobalTableName *string
80
81	// The Regions where the global table needs to be created.
82	//
83	// This member is required.
84	ReplicationGroup []types.Replica
85}
86
87type CreateGlobalTableOutput struct {
88
89	// Contains the details of the global table.
90	GlobalTableDescription *types.GlobalTableDescription
91
92	// Metadata pertaining to the operation's result.
93	ResultMetadata middleware.Metadata
94}
95
96func addOperationCreateGlobalTableMiddlewares(stack *middleware.Stack, options Options) (err error) {
97	err = stack.Serialize.Add(&awsAwsjson10_serializeOpCreateGlobalTable{}, middleware.After)
98	if err != nil {
99		return err
100	}
101	err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpCreateGlobalTable{}, middleware.After)
102	if err != nil {
103		return err
104	}
105	if err = addSetLoggerMiddleware(stack, options); err != nil {
106		return err
107	}
108	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
109		return err
110	}
111	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
112		return err
113	}
114	if err = addResolveEndpointMiddleware(stack, options); err != nil {
115		return err
116	}
117	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
118		return err
119	}
120	if err = addRetryMiddlewares(stack, options); err != nil {
121		return err
122	}
123	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
124		return err
125	}
126	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
127		return err
128	}
129	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
130		return err
131	}
132	if err = addClientUserAgent(stack); err != nil {
133		return err
134	}
135	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
136		return err
137	}
138	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
139		return err
140	}
141	if err = addOpCreateGlobalTableValidationMiddleware(stack); err != nil {
142		return err
143	}
144	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateGlobalTable(options.Region), middleware.Before); err != nil {
145		return err
146	}
147	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
148		return err
149	}
150	if err = addResponseErrorMiddleware(stack); err != nil {
151		return err
152	}
153	if err = addValidateResponseChecksum(stack, options); err != nil {
154		return err
155	}
156	if err = addAcceptEncodingGzip(stack, options); err != nil {
157		return err
158	}
159	if err = addRequestResponseLogging(stack, options); err != nil {
160		return err
161	}
162	return nil
163}
164
165func newServiceMetadataMiddleware_opCreateGlobalTable(region string) *awsmiddleware.RegisterServiceMetadata {
166	return &awsmiddleware.RegisterServiceMetadata{
167		Region:        region,
168		ServiceID:     ServiceID,
169		SigningName:   "dynamodb",
170		OperationName: "CreateGlobalTable",
171	}
172}
173