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// The CreateTable operation adds a new table to your account. In an AWS account,
15// table names must be unique within each Region. That is, you can have two tables
16// with same name if you create the tables in different Regions. CreateTable is an
17// asynchronous operation. Upon receiving a CreateTable request, DynamoDB
18// immediately returns a response with a TableStatus of CREATING. After the table
19// is created, DynamoDB sets the TableStatus to ACTIVE. You can perform read and
20// write operations only on an ACTIVE table. You can optionally define secondary
21// indexes on the new table, as part of the CreateTable operation. If you want to
22// create multiple tables with secondary indexes on them, you must create the
23// tables sequentially. Only one table with secondary indexes can be in the
24// CREATING state at any given time. You can use the DescribeTable action to check
25// the table status.
26func (c *Client) CreateTable(ctx context.Context, params *CreateTableInput, optFns ...func(*Options)) (*CreateTableOutput, error) {
27	if params == nil {
28		params = &CreateTableInput{}
29	}
30
31	result, metadata, err := c.invokeOperation(ctx, "CreateTable", params, optFns, addOperationCreateTableMiddlewares)
32	if err != nil {
33		return nil, err
34	}
35
36	out := result.(*CreateTableOutput)
37	out.ResultMetadata = metadata
38	return out, nil
39}
40
41// Represents the input of a CreateTable operation.
42type CreateTableInput struct {
43
44	// An array of attributes that describe the key schema for the table and indexes.
45	//
46	// This member is required.
47	AttributeDefinitions []types.AttributeDefinition
48
49	// Specifies the attributes that make up the primary key for a table or an index.
50	// The attributes in KeySchema must also be defined in the AttributeDefinitions
51	// array. For more information, see Data Model
52	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DataModel.html)
53	// in the Amazon DynamoDB Developer Guide. Each KeySchemaElement in the array is
54	// composed of:
55	//
56	// * AttributeName - The name of this key attribute.
57	//
58	// * KeyType - The
59	// role that the key attribute will assume:
60	//
61	// * HASH - partition key
62	//
63	// * RANGE - sort
64	// key
65	//
66	// The partition key of an item is also known as its hash attribute. The term
67	// "hash attribute" derives from the DynamoDB usage of an internal hash function to
68	// evenly distribute data items across partitions, based on their partition key
69	// values. The sort key of an item is also known as its range attribute. The term
70	// "range attribute" derives from the way DynamoDB stores items with the same
71	// partition key physically close together, in sorted order by the sort key value.
72	// For a simple primary key (partition key), you must provide exactly one element
73	// with a KeyType of HASH. For a composite primary key (partition key and sort
74	// key), you must provide exactly two elements, in this order: The first element
75	// must have a KeyType of HASH, and the second element must have a KeyType of
76	// RANGE. For more information, see Working with Tables
77	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.html#WorkingWithTables.primary.key)
78	// in the Amazon DynamoDB Developer Guide.
79	//
80	// This member is required.
81	KeySchema []types.KeySchemaElement
82
83	// The name of the table to create.
84	//
85	// This member is required.
86	TableName *string
87
88	// Controls how you are charged for read and write throughput and how you manage
89	// capacity. This setting can be changed later.
90	//
91	// * PROVISIONED - We recommend using
92	// PROVISIONED for predictable workloads. PROVISIONED sets the billing mode to
93	// Provisioned Mode
94	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.html#HowItWorks.ProvisionedThroughput.Manual).
95	//
96	// *
97	// PAY_PER_REQUEST - We recommend using PAY_PER_REQUEST for unpredictable
98	// workloads. PAY_PER_REQUEST sets the billing mode to On-Demand Mode
99	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadWriteCapacityMode.html#HowItWorks.OnDemand).
100	BillingMode types.BillingMode
101
102	// One or more global secondary indexes (the maximum is 20) to be created on the
103	// table. Each global secondary index in the array includes the following:
104	//
105	// *
106	// IndexName - The name of the global secondary index. Must be unique only for this
107	// table.
108	//
109	// * KeySchema - Specifies the key schema for the global secondary
110	// index.
111	//
112	// * Projection - Specifies attributes that are copied (projected) from the
113	// table into the index. These are in addition to the primary key attributes and
114	// index key attributes, which are automatically projected. Each attribute
115	// specification is composed of:
116	//
117	// * ProjectionType - One of the following:
118	//
119	// *
120	// KEYS_ONLY - Only the index and primary keys are projected into the index.
121	//
122	// *
123	// INCLUDE - Only the specified table attributes are projected into the index. The
124	// list of projected attributes is in NonKeyAttributes.
125	//
126	// * ALL - All of the table
127	// attributes are projected into the index.
128	//
129	// * NonKeyAttributes - A list of one or
130	// more non-key attribute names that are projected into the secondary index. The
131	// total count of attributes provided in NonKeyAttributes, summed across all of the
132	// secondary indexes, must not exceed 100. If you project the same attribute into
133	// two different indexes, this counts as two distinct attributes when determining
134	// the total.
135	//
136	// * ProvisionedThroughput - The provisioned throughput settings for
137	// the global secondary index, consisting of read and write capacity units.
138	GlobalSecondaryIndexes []types.GlobalSecondaryIndex
139
140	// One or more local secondary indexes (the maximum is 5) to be created on the
141	// table. Each index is scoped to a given partition key value. There is a 10 GB
142	// size limit per partition key value; otherwise, the size of a local secondary
143	// index is unconstrained. Each local secondary index in the array includes the
144	// following:
145	//
146	// * IndexName - The name of the local secondary index. Must be unique
147	// only for this table.
148	//
149	// * KeySchema - Specifies the key schema for the local
150	// secondary index. The key schema must begin with the same partition key as the
151	// table.
152	//
153	// * Projection - Specifies attributes that are copied (projected) from the
154	// table into the index. These are in addition to the primary key attributes and
155	// index key attributes, which are automatically projected. Each attribute
156	// specification is composed of:
157	//
158	// * ProjectionType - One of the following:
159	//
160	// *
161	// KEYS_ONLY - Only the index and primary keys are projected into the index.
162	//
163	// *
164	// INCLUDE - Only the specified table attributes are projected into the index. The
165	// list of projected attributes is in NonKeyAttributes.
166	//
167	// * ALL - All of the table
168	// attributes are projected into the index.
169	//
170	// * NonKeyAttributes - A list of one or
171	// more non-key attribute names that are projected into the secondary index. The
172	// total count of attributes provided in NonKeyAttributes, summed across all of the
173	// secondary indexes, must not exceed 100. If you project the same attribute into
174	// two different indexes, this counts as two distinct attributes when determining
175	// the total.
176	LocalSecondaryIndexes []types.LocalSecondaryIndex
177
178	// Represents the provisioned throughput settings for a specified table or index.
179	// The settings can be modified using the UpdateTable operation. If you set
180	// BillingMode as PROVISIONED, you must specify this property. If you set
181	// BillingMode as PAY_PER_REQUEST, you cannot specify this property. For current
182	// minimum and maximum provisioned throughput values, see Service, Account, and
183	// Table Quotas
184	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html)
185	// in the Amazon DynamoDB Developer Guide.
186	ProvisionedThroughput *types.ProvisionedThroughput
187
188	// Represents the settings used to enable server-side encryption.
189	SSESpecification *types.SSESpecification
190
191	// The settings for DynamoDB Streams on the table. These settings consist of:
192	//
193	// *
194	// StreamEnabled - Indicates whether DynamoDB Streams is to be enabled (true) or
195	// disabled (false).
196	//
197	// * StreamViewType - When an item in the table is modified,
198	// StreamViewType determines what information is written to the table's stream.
199	// Valid values for StreamViewType are:
200	//
201	// * KEYS_ONLY - Only the key attributes of
202	// the modified item are written to the stream.
203	//
204	// * NEW_IMAGE - The entire item, as
205	// it appears after it was modified, is written to the stream.
206	//
207	// * OLD_IMAGE - The
208	// entire item, as it appeared before it was modified, is written to the stream.
209	//
210	// *
211	// NEW_AND_OLD_IMAGES - Both the new and the old item images of the item are
212	// written to the stream.
213	StreamSpecification *types.StreamSpecification
214
215	// A list of key-value pairs to label the table. For more information, see Tagging
216	// for DynamoDB
217	// (https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Tagging.html).
218	Tags []types.Tag
219}
220
221// Represents the output of a CreateTable operation.
222type CreateTableOutput struct {
223
224	// Represents the properties of the table.
225	TableDescription *types.TableDescription
226
227	// Metadata pertaining to the operation's result.
228	ResultMetadata middleware.Metadata
229}
230
231func addOperationCreateTableMiddlewares(stack *middleware.Stack, options Options) (err error) {
232	err = stack.Serialize.Add(&awsAwsjson10_serializeOpCreateTable{}, middleware.After)
233	if err != nil {
234		return err
235	}
236	err = stack.Deserialize.Add(&awsAwsjson10_deserializeOpCreateTable{}, middleware.After)
237	if err != nil {
238		return err
239	}
240	if err = addSetLoggerMiddleware(stack, options); err != nil {
241		return err
242	}
243	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
244		return err
245	}
246	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
247		return err
248	}
249	if err = addResolveEndpointMiddleware(stack, options); err != nil {
250		return err
251	}
252	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
253		return err
254	}
255	if err = addRetryMiddlewares(stack, options); err != nil {
256		return err
257	}
258	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
259		return err
260	}
261	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
262		return err
263	}
264	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
265		return err
266	}
267	if err = addClientUserAgent(stack); err != nil {
268		return err
269	}
270	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
271		return err
272	}
273	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
274		return err
275	}
276	if err = addOpCreateTableValidationMiddleware(stack); err != nil {
277		return err
278	}
279	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateTable(options.Region), middleware.Before); err != nil {
280		return err
281	}
282	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
283		return err
284	}
285	if err = addResponseErrorMiddleware(stack); err != nil {
286		return err
287	}
288	if err = addValidateResponseChecksum(stack, options); err != nil {
289		return err
290	}
291	if err = addAcceptEncodingGzip(stack, options); err != nil {
292		return err
293	}
294	if err = addRequestResponseLogging(stack, options); err != nil {
295		return err
296	}
297	return nil
298}
299
300func newServiceMetadataMiddleware_opCreateTable(region string) *awsmiddleware.RegisterServiceMetadata {
301	return &awsmiddleware.RegisterServiceMetadata{
302		Region:        region,
303		ServiceID:     ServiceID,
304		SigningName:   "dynamodb",
305		OperationName: "CreateTable",
306	}
307}
308