1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ec2
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/ec2/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12	"time"
13)
14
15// Creates an EBS volume that can be attached to an instance in the same
16// Availability Zone. You can create a new empty volume or restore a volume from an
17// EBS snapshot. Any AWS Marketplace product codes from the snapshot are propagated
18// to the volume. You can create encrypted volumes. Encrypted volumes must be
19// attached to instances that support Amazon EBS encryption. Volumes that are
20// created from encrypted snapshots are also automatically encrypted. For more
21// information, see Amazon EBS encryption
22// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html) in the
23// Amazon Elastic Compute Cloud User Guide. You can tag your volumes during
24// creation. For more information, see Tagging your Amazon EC2 resources
25// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html) in the
26// Amazon Elastic Compute Cloud User Guide. For more information, see Creating an
27// Amazon EBS volume
28// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-creating-volume.html)
29// in the Amazon Elastic Compute Cloud User Guide.
30func (c *Client) CreateVolume(ctx context.Context, params *CreateVolumeInput, optFns ...func(*Options)) (*CreateVolumeOutput, error) {
31	if params == nil {
32		params = &CreateVolumeInput{}
33	}
34
35	result, metadata, err := c.invokeOperation(ctx, "CreateVolume", params, optFns, addOperationCreateVolumeMiddlewares)
36	if err != nil {
37		return nil, err
38	}
39
40	out := result.(*CreateVolumeOutput)
41	out.ResultMetadata = metadata
42	return out, nil
43}
44
45type CreateVolumeInput struct {
46
47	// The Availability Zone in which to create the volume.
48	//
49	// This member is required.
50	AvailabilityZone *string
51
52	// Checks whether you have the required permissions for the action, without
53	// actually making the request, and provides an error response. If you have the
54	// required permissions, the error response is DryRunOperation. Otherwise, it is
55	// UnauthorizedOperation.
56	DryRun bool
57
58	// Indicates whether the volume should be encrypted. The effect of setting the
59	// encryption state to true depends on the volume origin (new or from a snapshot),
60	// starting encryption state, ownership, and whether encryption by default is
61	// enabled. For more information, see Encryption by default
62	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html#encryption-by-default)
63	// in the Amazon Elastic Compute Cloud User Guide. Encrypted Amazon EBS volumes
64	// must be attached to instances that support Amazon EBS encryption. For more
65	// information, see Supported instance types
66	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html#EBSEncryption_supported_instances).
67	Encrypted bool
68
69	// The number of I/O operations per second (IOPS). For gp3, io1, and io2 volumes,
70	// this represents the number of IOPS that are provisioned for the volume. For gp2
71	// volumes, this represents the baseline performance of the volume and the rate at
72	// which the volume accumulates I/O credits for bursting. The following are the
73	// supported values for each volume type:
74	//
75	// * gp3: 3,000-16,000 IOPS
76	//
77	// * io1:
78	// 100-64,000 IOPS
79	//
80	// * io2: 100-64,000 IOPS
81	//
82	// For io1 and io2 volumes, we guarantee
83	// 64,000 IOPS only for Instances built on the Nitro System
84	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#ec2-nitro-instances).
85	// Other instance families guarantee performance up to 32,000 IOPS. This parameter
86	// is required for io1 and io2 volumes. The default for gp3 volumes is 3,000 IOPS.
87	// This parameter is not supported for gp2, st1, sc1, or standard volumes.
88	Iops int32
89
90	// The identifier of the AWS Key Management Service (AWS KMS) customer master key
91	// (CMK) to use for Amazon EBS encryption. If this parameter is not specified, your
92	// AWS managed CMK for EBS is used. If KmsKeyId is specified, the encrypted state
93	// must be true. You can specify the CMK using any of the following:
94	//
95	// * Key ID. For
96	// example, 1234abcd-12ab-34cd-56ef-1234567890ab.
97	//
98	// * Key alias. For example,
99	// alias/ExampleAlias.
100	//
101	// * Key ARN. For example,
102	// arn:aws:kms:us-east-1:012345678910:key/1234abcd-12ab-34cd-56ef-1234567890ab.
103	//
104	// *
105	// Alias ARN. For example,
106	// arn:aws:kms:us-east-1:012345678910:alias/ExampleAlias.
107	//
108	// AWS authenticates the
109	// CMK asynchronously. Therefore, if you specify an ID, alias, or ARN that is not
110	// valid, the action can appear to complete, but eventually fails.
111	KmsKeyId *string
112
113	// Indicates whether to enable Amazon EBS Multi-Attach. If you enable Multi-Attach,
114	// you can attach the volume to up to 16 Instances built on the Nitro System
115	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#ec2-nitro-instances)
116	// in the same Availability Zone. This parameter is supported with io1 and io2
117	// volumes only. For more information, see  Amazon EBS Multi-Attach
118	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-volumes-multi.html) in
119	// the Amazon Elastic Compute Cloud User Guide.
120	MultiAttachEnabled bool
121
122	// The Amazon Resource Name (ARN) of the Outpost.
123	OutpostArn *string
124
125	// The size of the volume, in GiBs. You must specify either a snapshot ID or a
126	// volume size. If you specify a snapshot, the default is the snapshot size. You
127	// can specify a volume size that is equal to or larger than the snapshot size. The
128	// following are the supported volumes sizes for each volume type:
129	//
130	// * gp2 and gp3:
131	// 1-16,384
132	//
133	// * io1 and io2: 4-16,384
134	//
135	// * st1 and sc1: 125-16,384
136	//
137	// * standard:
138	// 1-1,024
139	Size int32
140
141	// The snapshot from which to create the volume. You must specify either a snapshot
142	// ID or a volume size.
143	SnapshotId *string
144
145	// The tags to apply to the volume during creation.
146	TagSpecifications []types.TagSpecification
147
148	// The throughput to provision for a volume, with a maximum of 1,000 MiB/s. This
149	// parameter is valid only for gp3 volumes. Valid Range: Minimum value of 125.
150	// Maximum value of 1000.
151	Throughput int32
152
153	// The volume type. This parameter can be one of the following values:
154	//
155	// * General
156	// Purpose SSD: gp2 | gp3
157	//
158	// * Provisioned IOPS SSD: io1 | io2
159	//
160	// * Throughput
161	// Optimized HDD: st1
162	//
163	// * Cold HDD: sc1
164	//
165	// * Magnetic: standard
166	//
167	// For more information,
168	// see Amazon EBS volume types
169	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSVolumeTypes.html) in the
170	// Amazon Elastic Compute Cloud User Guide. Default: gp2
171	VolumeType types.VolumeType
172}
173
174// Describes a volume.
175type CreateVolumeOutput struct {
176
177	// Information about the volume attachments.
178	Attachments []types.VolumeAttachment
179
180	// The Availability Zone for the volume.
181	AvailabilityZone *string
182
183	// The time stamp when volume creation was initiated.
184	CreateTime *time.Time
185
186	// Indicates whether the volume is encrypted.
187	Encrypted bool
188
189	// Indicates whether the volume was created using fast snapshot restore.
190	FastRestored bool
191
192	// The number of I/O operations per second (IOPS). For gp3, io1, and io2 volumes,
193	// this represents the number of IOPS that are provisioned for the volume. For gp2
194	// volumes, this represents the baseline performance of the volume and the rate at
195	// which the volume accumulates I/O credits for bursting.
196	Iops int32
197
198	// The Amazon Resource Name (ARN) of the AWS Key Management Service (AWS KMS)
199	// customer master key (CMK) that was used to protect the volume encryption key for
200	// the volume.
201	KmsKeyId *string
202
203	// Indicates whether Amazon EBS Multi-Attach is enabled.
204	MultiAttachEnabled bool
205
206	// The Amazon Resource Name (ARN) of the Outpost.
207	OutpostArn *string
208
209	// The size of the volume, in GiBs.
210	Size int32
211
212	// The snapshot from which the volume was created, if applicable.
213	SnapshotId *string
214
215	// The volume state.
216	State types.VolumeState
217
218	// Any tags assigned to the volume.
219	Tags []types.Tag
220
221	// The throughput that the volume supports, in MiB/s.
222	Throughput int32
223
224	// The ID of the volume.
225	VolumeId *string
226
227	// The volume type.
228	VolumeType types.VolumeType
229
230	// Metadata pertaining to the operation's result.
231	ResultMetadata middleware.Metadata
232}
233
234func addOperationCreateVolumeMiddlewares(stack *middleware.Stack, options Options) (err error) {
235	err = stack.Serialize.Add(&awsEc2query_serializeOpCreateVolume{}, middleware.After)
236	if err != nil {
237		return err
238	}
239	err = stack.Deserialize.Add(&awsEc2query_deserializeOpCreateVolume{}, middleware.After)
240	if err != nil {
241		return err
242	}
243	if err = addSetLoggerMiddleware(stack, options); err != nil {
244		return err
245	}
246	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
247		return err
248	}
249	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
250		return err
251	}
252	if err = addResolveEndpointMiddleware(stack, options); err != nil {
253		return err
254	}
255	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
256		return err
257	}
258	if err = addRetryMiddlewares(stack, options); err != nil {
259		return err
260	}
261	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
262		return err
263	}
264	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
265		return err
266	}
267	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
268		return err
269	}
270	if err = addClientUserAgent(stack); err != nil {
271		return err
272	}
273	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
274		return err
275	}
276	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
277		return err
278	}
279	if err = addOpCreateVolumeValidationMiddleware(stack); err != nil {
280		return err
281	}
282	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateVolume(options.Region), middleware.Before); err != nil {
283		return err
284	}
285	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
286		return err
287	}
288	if err = addResponseErrorMiddleware(stack); err != nil {
289		return err
290	}
291	if err = addRequestResponseLogging(stack, options); err != nil {
292		return err
293	}
294	return nil
295}
296
297func newServiceMetadataMiddleware_opCreateVolume(region string) *awsmiddleware.RegisterServiceMetadata {
298	return &awsmiddleware.RegisterServiceMetadata{
299		Region:        region,
300		ServiceID:     ServiceID,
301		SigningName:   "ec2",
302		OperationName: "CreateVolume",
303	}
304}
305