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// Launches an EC2 Fleet. You can create a single EC2 Fleet that includes multiple
16// launch specifications that vary by instance type, AMI, Availability Zone, or
17// subnet. For more information, see Launching an EC2 Fleet
18// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet.html) in the
19// Amazon EC2 User Guide.
20func (c *Client) CreateFleet(ctx context.Context, params *CreateFleetInput, optFns ...func(*Options)) (*CreateFleetOutput, error) {
21	if params == nil {
22		params = &CreateFleetInput{}
23	}
24
25	result, metadata, err := c.invokeOperation(ctx, "CreateFleet", params, optFns, c.addOperationCreateFleetMiddlewares)
26	if err != nil {
27		return nil, err
28	}
29
30	out := result.(*CreateFleetOutput)
31	out.ResultMetadata = metadata
32	return out, nil
33}
34
35type CreateFleetInput struct {
36
37	// The configuration for the EC2 Fleet.
38	//
39	// This member is required.
40	LaunchTemplateConfigs []types.FleetLaunchTemplateConfigRequest
41
42	// The number of units to request.
43	//
44	// This member is required.
45	TargetCapacitySpecification *types.TargetCapacitySpecificationRequest
46
47	// Unique, case-sensitive identifier that you provide to ensure the idempotency of
48	// the request. For more information, see Ensuring Idempotency
49	// (https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Run_Instance_Idempotency.html).
50	ClientToken *string
51
52	// Reserved.
53	Context *string
54
55	// Checks whether you have the required permissions for the action, without
56	// actually making the request, and provides an error response. If you have the
57	// required permissions, the error response is DryRunOperation. Otherwise, it is
58	// UnauthorizedOperation.
59	DryRun *bool
60
61	// Indicates whether running instances should be terminated if the total target
62	// capacity of the EC2 Fleet is decreased below the current size of the EC2 Fleet.
63	ExcessCapacityTerminationPolicy types.FleetExcessCapacityTerminationPolicy
64
65	// Describes the configuration of On-Demand Instances in an EC2 Fleet.
66	OnDemandOptions *types.OnDemandOptionsRequest
67
68	// Indicates whether EC2 Fleet should replace unhealthy Spot Instances. Supported
69	// only for fleets of type maintain. For more information, see EC2 Fleet health
70	// checks
71	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/manage-ec2-fleet.html#ec2-fleet-health-checks)
72	// in the Amazon EC2 User Guide.
73	ReplaceUnhealthyInstances *bool
74
75	// Describes the configuration of Spot Instances in an EC2 Fleet.
76	SpotOptions *types.SpotOptionsRequest
77
78	// The key-value pair for tagging the EC2 Fleet request on creation. For more
79	// information, see Tagging your resources
80	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-resources).
81	// If the fleet type is instant, specify a resource type of fleet to tag the fleet
82	// or instance to tag the instances at launch. If the fleet type is maintain or
83	// request, specify a resource type of fleet to tag the fleet. You cannot specify a
84	// resource type of instance. To tag instances at launch, specify the tags in a
85	// launch template
86	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html#create-launch-template).
87	TagSpecifications []types.TagSpecification
88
89	// Indicates whether running instances should be terminated when the EC2 Fleet
90	// expires.
91	TerminateInstancesWithExpiration *bool
92
93	// The fleet type. The default value is maintain.
94	//
95	// * maintain - The EC2 Fleet
96	// places an asynchronous request for your desired capacity, and continues to
97	// maintain your desired Spot capacity by replenishing interrupted Spot
98	// Instances.
99	//
100	// * request - The EC2 Fleet places an asynchronous one-time request
101	// for your desired capacity, but does submit Spot requests in alternative capacity
102	// pools if Spot capacity is unavailable, and does not maintain Spot capacity if
103	// Spot Instances are interrupted.
104	//
105	// * instant - The EC2 Fleet places a synchronous
106	// one-time request for your desired capacity, and returns errors for any instances
107	// that could not be launched.
108	//
109	// For more information, see EC2 Fleet request types
110	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-configuration-strategies.html#ec2-fleet-request-type)
111	// in the Amazon EC2 User Guide.
112	Type types.FleetType
113
114	// The start date and time of the request, in UTC format (for example,
115	// YYYY-MM-DDTHH:MM:SSZ). The default is to start fulfilling the request
116	// immediately.
117	ValidFrom *time.Time
118
119	// The end date and time of the request, in UTC format (for example,
120	// YYYY-MM-DDTHH:MM:SSZ). At this point, no new EC2 Fleet requests are placed or
121	// able to fulfill the request. If no value is specified, the request remains until
122	// you cancel it.
123	ValidUntil *time.Time
124
125	noSmithyDocumentSerde
126}
127
128type CreateFleetOutput struct {
129
130	// Information about the instances that could not be launched by the fleet.
131	// Supported only for fleets of type instant.
132	Errors []types.CreateFleetError
133
134	// The ID of the EC2 Fleet.
135	FleetId *string
136
137	// Information about the instances that were launched by the fleet. Supported only
138	// for fleets of type instant.
139	Instances []types.CreateFleetInstance
140
141	// Metadata pertaining to the operation's result.
142	ResultMetadata middleware.Metadata
143
144	noSmithyDocumentSerde
145}
146
147func (c *Client) addOperationCreateFleetMiddlewares(stack *middleware.Stack, options Options) (err error) {
148	err = stack.Serialize.Add(&awsEc2query_serializeOpCreateFleet{}, middleware.After)
149	if err != nil {
150		return err
151	}
152	err = stack.Deserialize.Add(&awsEc2query_deserializeOpCreateFleet{}, middleware.After)
153	if err != nil {
154		return err
155	}
156	if err = addSetLoggerMiddleware(stack, options); err != nil {
157		return err
158	}
159	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
160		return err
161	}
162	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
163		return err
164	}
165	if err = addResolveEndpointMiddleware(stack, options); err != nil {
166		return err
167	}
168	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
169		return err
170	}
171	if err = addRetryMiddlewares(stack, options); err != nil {
172		return err
173	}
174	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
175		return err
176	}
177	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
178		return err
179	}
180	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
181		return err
182	}
183	if err = addClientUserAgent(stack); err != nil {
184		return err
185	}
186	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
187		return err
188	}
189	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
190		return err
191	}
192	if err = addOpCreateFleetValidationMiddleware(stack); err != nil {
193		return err
194	}
195	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateFleet(options.Region), middleware.Before); err != nil {
196		return err
197	}
198	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
199		return err
200	}
201	if err = addResponseErrorMiddleware(stack); err != nil {
202		return err
203	}
204	if err = addRequestResponseLogging(stack, options); err != nil {
205		return err
206	}
207	return nil
208}
209
210func newServiceMetadataMiddleware_opCreateFleet(region string) *awsmiddleware.RegisterServiceMetadata {
211	return &awsmiddleware.RegisterServiceMetadata{
212		Region:        region,
213		ServiceID:     ServiceID,
214		SigningName:   "ec2",
215		OperationName: "CreateFleet",
216	}
217}
218