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 a new Capacity Reservation with the specified attributes. Capacity
16// Reservations enable you to reserve capacity for your Amazon EC2 instances in a
17// specific Availability Zone for any duration. This gives you the flexibility to
18// selectively add capacity reservations and still get the Regional RI discounts
19// for that usage. By creating Capacity Reservations, you ensure that you always
20// have access to Amazon EC2 capacity when you need it, for as long as you need it.
21// For more information, see Capacity Reservations
22// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-capacity-reservations.html)
23// in the Amazon EC2 User Guide. Your request to create a Capacity Reservation
24// could fail if Amazon EC2 does not have sufficient capacity to fulfill the
25// request. If your request fails due to Amazon EC2 capacity constraints, either
26// try again at a later time, try in a different Availability Zone, or request a
27// smaller capacity reservation. If your application is flexible across instance
28// types and sizes, try to create a Capacity Reservation with different instance
29// attributes. Your request could also fail if the requested quantity exceeds your
30// On-Demand Instance limit for the selected instance type. If your request fails
31// due to limit constraints, increase your On-Demand Instance limit for the
32// required instance type and try again. For more information about increasing your
33// instance limits, see Amazon EC2 Service Quotas
34// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-resource-limits.html)
35// in the Amazon EC2 User Guide.
36func (c *Client) CreateCapacityReservation(ctx context.Context, params *CreateCapacityReservationInput, optFns ...func(*Options)) (*CreateCapacityReservationOutput, error) {
37	if params == nil {
38		params = &CreateCapacityReservationInput{}
39	}
40
41	result, metadata, err := c.invokeOperation(ctx, "CreateCapacityReservation", params, optFns, addOperationCreateCapacityReservationMiddlewares)
42	if err != nil {
43		return nil, err
44	}
45
46	out := result.(*CreateCapacityReservationOutput)
47	out.ResultMetadata = metadata
48	return out, nil
49}
50
51type CreateCapacityReservationInput struct {
52
53	// The number of instances for which to reserve capacity.
54	//
55	// This member is required.
56	InstanceCount int32
57
58	// The type of operating system for which to reserve capacity.
59	//
60	// This member is required.
61	InstancePlatform types.CapacityReservationInstancePlatform
62
63	// The instance type for which to reserve capacity. For more information, see
64	// Instance types
65	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html) in the
66	// Amazon EC2 User Guide.
67	//
68	// This member is required.
69	InstanceType *string
70
71	// The Availability Zone in which to create the Capacity Reservation.
72	AvailabilityZone *string
73
74	// The ID of the Availability Zone in which to create the Capacity Reservation.
75	AvailabilityZoneId *string
76
77	// Unique, case-sensitive identifier that you provide to ensure the idempotency of
78	// the request. For more information, see Ensure Idempotency
79	// (https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html).
80	ClientToken *string
81
82	// Checks whether you have the required permissions for the action, without
83	// actually making the request, and provides an error response. If you have the
84	// required permissions, the error response is DryRunOperation. Otherwise, it is
85	// UnauthorizedOperation.
86	DryRun bool
87
88	// Indicates whether the Capacity Reservation supports EBS-optimized instances.
89	// This optimization provides dedicated throughput to Amazon EBS and an optimized
90	// configuration stack to provide optimal I/O performance. This optimization isn't
91	// available with all instance types. Additional usage charges apply when using an
92	// EBS- optimized instance.
93	EbsOptimized bool
94
95	// The date and time at which the Capacity Reservation expires. When a Capacity
96	// Reservation expires, the reserved capacity is released and you can no longer
97	// launch instances into it. The Capacity Reservation's state changes to expired
98	// when it reaches its end date and time. You must provide an EndDate value if
99	// EndDateType is limited. Omit EndDate if EndDateType is unlimited. If the
100	// EndDateType is limited, the Capacity Reservation is cancelled within an hour
101	// from the specified time. For example, if you specify 5/31/2019, 13:30:55, the
102	// Capacity Reservation is guaranteed to end between 13:30:55 and 14:30:55 on
103	// 5/31/2019.
104	EndDate *time.Time
105
106	// Indicates the way in which the Capacity Reservation ends. A Capacity Reservation
107	// can have one of the following end types:
108	//
109	// * unlimited - The Capacity Reservation
110	// remains active until you explicitly cancel it. Do not provide an EndDate if the
111	// EndDateType is unlimited.
112	//
113	// * limited - The Capacity Reservation expires
114	// automatically at a specified date and time. You must provide an EndDate value if
115	// the EndDateType value is limited.
116	EndDateType types.EndDateType
117
118	// Indicates whether the Capacity Reservation supports instances with temporary,
119	// block-level storage.
120	EphemeralStorage bool
121
122	// Indicates the type of instance launches that the Capacity Reservation accepts.
123	// The options include:
124	//
125	// * open - The Capacity Reservation automatically matches
126	// all instances that have matching attributes (instance type, platform, and
127	// Availability Zone). Instances that have matching attributes run in the Capacity
128	// Reservation automatically without specifying any additional parameters.
129	//
130	// *
131	// targeted - The Capacity Reservation only accepts instances that have matching
132	// attributes (instance type, platform, and Availability Zone), and explicitly
133	// target the Capacity Reservation. This ensures that only permitted instances can
134	// use the reserved capacity.
135	//
136	// Default: open
137	InstanceMatchCriteria types.InstanceMatchCriteria
138
139	// The tags to apply to the Capacity Reservation during launch.
140	TagSpecifications []types.TagSpecification
141
142	// Indicates the tenancy of the Capacity Reservation. A Capacity Reservation can
143	// have one of the following tenancy settings:
144	//
145	// * default - The Capacity
146	// Reservation is created on hardware that is shared with other AWS accounts.
147	//
148	// *
149	// dedicated - The Capacity Reservation is created on single-tenant hardware that
150	// is dedicated to a single AWS account.
151	Tenancy types.CapacityReservationTenancy
152}
153
154type CreateCapacityReservationOutput struct {
155
156	// Information about the Capacity Reservation.
157	CapacityReservation *types.CapacityReservation
158
159	// Metadata pertaining to the operation's result.
160	ResultMetadata middleware.Metadata
161}
162
163func addOperationCreateCapacityReservationMiddlewares(stack *middleware.Stack, options Options) (err error) {
164	err = stack.Serialize.Add(&awsEc2query_serializeOpCreateCapacityReservation{}, middleware.After)
165	if err != nil {
166		return err
167	}
168	err = stack.Deserialize.Add(&awsEc2query_deserializeOpCreateCapacityReservation{}, middleware.After)
169	if err != nil {
170		return err
171	}
172	if err = addSetLoggerMiddleware(stack, options); err != nil {
173		return err
174	}
175	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
176		return err
177	}
178	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
179		return err
180	}
181	if err = addResolveEndpointMiddleware(stack, options); err != nil {
182		return err
183	}
184	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
185		return err
186	}
187	if err = addRetryMiddlewares(stack, options); err != nil {
188		return err
189	}
190	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
191		return err
192	}
193	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
194		return err
195	}
196	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
197		return err
198	}
199	if err = addClientUserAgent(stack); err != nil {
200		return err
201	}
202	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
203		return err
204	}
205	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
206		return err
207	}
208	if err = addOpCreateCapacityReservationValidationMiddleware(stack); err != nil {
209		return err
210	}
211	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateCapacityReservation(options.Region), middleware.Before); err != nil {
212		return err
213	}
214	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
215		return err
216	}
217	if err = addResponseErrorMiddleware(stack); err != nil {
218		return err
219	}
220	if err = addRequestResponseLogging(stack, options); err != nil {
221		return err
222	}
223	return nil
224}
225
226func newServiceMetadataMiddleware_opCreateCapacityReservation(region string) *awsmiddleware.RegisterServiceMetadata {
227	return &awsmiddleware.RegisterServiceMetadata{
228		Region:        region,
229		ServiceID:     ServiceID,
230		SigningName:   "ec2",
231		OperationName: "CreateCapacityReservation",
232	}
233}
234