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, 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	// 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 running instances should be terminated if the total target
59	// capacity of the EC2 Fleet is decreased below the current size of the EC2 Fleet.
60	ExcessCapacityTerminationPolicy types.FleetExcessCapacityTerminationPolicy
61
62	// Describes the configuration of On-Demand Instances in an EC2 Fleet.
63	OnDemandOptions *types.OnDemandOptionsRequest
64
65	// Indicates whether EC2 Fleet should replace unhealthy instances.
66	ReplaceUnhealthyInstances bool
67
68	// Describes the configuration of Spot Instances in an EC2 Fleet.
69	SpotOptions *types.SpotOptionsRequest
70
71	// The key-value pair for tagging the EC2 Fleet request on creation. The value for
72	// ResourceType must be fleet, otherwise the fleet request fails. To tag instances
73	// at launch, specify the tags in the launch template
74	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html#create-launch-template).
75	// For information about tagging after launch, see Tagging your resources
76	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html#tag-resources).
77	TagSpecifications []types.TagSpecification
78
79	// Indicates whether running instances should be terminated when the EC2 Fleet
80	// expires.
81	TerminateInstancesWithExpiration bool
82
83	// The type of request. The default value is maintain.
84	//
85	// * maintain - The EC2 Fleet
86	// places an asynchronous request for your desired capacity, and continues to
87	// maintain your desired Spot capacity by replenishing interrupted Spot
88	// Instances.
89	//
90	// * request - The EC2 Fleet places an asynchronous one-time request
91	// for your desired capacity, but does submit Spot requests in alternative capacity
92	// pools if Spot capacity is unavailable, and does not maintain Spot capacity if
93	// Spot Instances are interrupted.
94	//
95	// * instant - The EC2 Fleet places a synchronous
96	// one-time request for your desired capacity, and returns errors for any instances
97	// that could not be launched.
98	//
99	// For more information, see EC2 Fleet request types
100	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-fleet-configuration-strategies.html#ec2-fleet-request-type)
101	// in the Amazon EC2 User Guide.
102	Type types.FleetType
103
104	// The start date and time of the request, in UTC format (for example,
105	// YYYY-MM-DDTHH:MM:SSZ). The default is to start fulfilling the request
106	// immediately.
107	ValidFrom *time.Time
108
109	// The end date and time of the request, in UTC format (for example,
110	// YYYY-MM-DDTHH:MM:SSZ). At this point, no new EC2 Fleet requests are placed or
111	// able to fulfill the request. If no value is specified, the request remains until
112	// you cancel it.
113	ValidUntil *time.Time
114}
115
116type CreateFleetOutput struct {
117
118	// Information about the instances that could not be launched by the fleet. Valid
119	// only when Type is set to instant.
120	Errors []types.CreateFleetError
121
122	// The ID of the EC2 Fleet.
123	FleetId *string
124
125	// Information about the instances that were launched by the fleet. Valid only when
126	// Type is set to instant.
127	Instances []types.CreateFleetInstance
128
129	// Metadata pertaining to the operation's result.
130	ResultMetadata middleware.Metadata
131}
132
133func addOperationCreateFleetMiddlewares(stack *middleware.Stack, options Options) (err error) {
134	err = stack.Serialize.Add(&awsEc2query_serializeOpCreateFleet{}, middleware.After)
135	if err != nil {
136		return err
137	}
138	err = stack.Deserialize.Add(&awsEc2query_deserializeOpCreateFleet{}, middleware.After)
139	if err != nil {
140		return err
141	}
142	if err = addSetLoggerMiddleware(stack, options); err != nil {
143		return err
144	}
145	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
146		return err
147	}
148	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
149		return err
150	}
151	if err = addResolveEndpointMiddleware(stack, options); err != nil {
152		return err
153	}
154	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
155		return err
156	}
157	if err = addRetryMiddlewares(stack, options); err != nil {
158		return err
159	}
160	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
161		return err
162	}
163	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
164		return err
165	}
166	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
167		return err
168	}
169	if err = addClientUserAgent(stack); err != nil {
170		return err
171	}
172	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
173		return err
174	}
175	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
176		return err
177	}
178	if err = addOpCreateFleetValidationMiddleware(stack); err != nil {
179		return err
180	}
181	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateFleet(options.Region), middleware.Before); err != nil {
182		return err
183	}
184	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
185		return err
186	}
187	if err = addResponseErrorMiddleware(stack); err != nil {
188		return err
189	}
190	if err = addRequestResponseLogging(stack, options); err != nil {
191		return err
192	}
193	return nil
194}
195
196func newServiceMetadataMiddleware_opCreateFleet(region string) *awsmiddleware.RegisterServiceMetadata {
197	return &awsmiddleware.RegisterServiceMetadata{
198		Region:        region,
199		ServiceID:     ServiceID,
200		SigningName:   "ec2",
201		OperationName: "CreateFleet",
202	}
203}
204