1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package gamelift
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/gamelift/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Retrieves information about a fleet's instances, including instance IDs,
16// connection data, and status. This operation can be used in the following
17// ways:
18//
19// * To get information on all instances that are deployed to a fleet's home
20// Region, provide the fleet ID.
21//
22// * To get information on all instances that are
23// deployed to a fleet's remote location, provide the fleet ID and location
24// name.
25//
26// * To get information on a specific instance in a fleet, provide the fleet
27// ID and instance ID.
28//
29// Use the pagination parameters to retrieve results as a set
30// of sequential pages. If successful, an Instance object is returned for each
31// requested instance. Instances are not returned in any particular order. Learn
32// more Remotely Access Fleet Instances
33// (https://docs.aws.amazon.com/gamelift/latest/developerguide/fleets-remote-access.html)Debug
34// Fleet Issues
35// (https://docs.aws.amazon.com/gamelift/latest/developerguide/fleets-creating-debug.html)
36// Related actions DescribeInstances | GetInstanceAccess |
37// DescribeEC2InstanceLimits | All APIs by task
38// (https://docs.aws.amazon.com/gamelift/latest/developerguide/reference-awssdk.html#reference-awssdk-resources-fleets)
39func (c *Client) DescribeInstances(ctx context.Context, params *DescribeInstancesInput, optFns ...func(*Options)) (*DescribeInstancesOutput, error) {
40	if params == nil {
41		params = &DescribeInstancesInput{}
42	}
43
44	result, metadata, err := c.invokeOperation(ctx, "DescribeInstances", params, optFns, addOperationDescribeInstancesMiddlewares)
45	if err != nil {
46		return nil, err
47	}
48
49	out := result.(*DescribeInstancesOutput)
50	out.ResultMetadata = metadata
51	return out, nil
52}
53
54// Represents the input for a request operation.
55type DescribeInstancesInput struct {
56
57	// A unique identifier for the fleet to retrieve instance information for. You can
58	// use either the fleet ID or ARN value.
59	//
60	// This member is required.
61	FleetId *string
62
63	// A unique identifier for an instance to retrieve. Specify an instance ID or leave
64	// blank to retrieve all instances in the fleet.
65	InstanceId *string
66
67	// The maximum number of results to return. Use this parameter with NextToken to
68	// get results as a set of sequential pages.
69	Limit *int32
70
71	// The name of a location to retrieve instance information for, in the form of an
72	// AWS Region code such as us-west-2.
73	Location *string
74
75	// A token that indicates the start of the next sequential page of results. Use the
76	// token that is returned with a previous call to this operation. To start at the
77	// beginning of the result set, do not specify a value.
78	NextToken *string
79}
80
81// Represents the returned data in response to a request operation.
82type DescribeInstancesOutput struct {
83
84	// A collection of objects containing properties for each instance returned.
85	Instances []types.Instance
86
87	// A token that indicates where to resume retrieving results on the next call to
88	// this operation. If no token is returned, these results represent the end of the
89	// list.
90	NextToken *string
91
92	// Metadata pertaining to the operation's result.
93	ResultMetadata middleware.Metadata
94}
95
96func addOperationDescribeInstancesMiddlewares(stack *middleware.Stack, options Options) (err error) {
97	err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribeInstances{}, middleware.After)
98	if err != nil {
99		return err
100	}
101	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribeInstances{}, middleware.After)
102	if err != nil {
103		return err
104	}
105	if err = addSetLoggerMiddleware(stack, options); err != nil {
106		return err
107	}
108	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
109		return err
110	}
111	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
112		return err
113	}
114	if err = addResolveEndpointMiddleware(stack, options); err != nil {
115		return err
116	}
117	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
118		return err
119	}
120	if err = addRetryMiddlewares(stack, options); err != nil {
121		return err
122	}
123	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
124		return err
125	}
126	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
127		return err
128	}
129	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
130		return err
131	}
132	if err = addClientUserAgent(stack); err != nil {
133		return err
134	}
135	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
136		return err
137	}
138	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
139		return err
140	}
141	if err = addOpDescribeInstancesValidationMiddleware(stack); err != nil {
142		return err
143	}
144	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeInstances(options.Region), middleware.Before); err != nil {
145		return err
146	}
147	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
148		return err
149	}
150	if err = addResponseErrorMiddleware(stack); err != nil {
151		return err
152	}
153	if err = addRequestResponseLogging(stack, options); err != nil {
154		return err
155	}
156	return nil
157}
158
159// DescribeInstancesAPIClient is a client that implements the DescribeInstances
160// operation.
161type DescribeInstancesAPIClient interface {
162	DescribeInstances(context.Context, *DescribeInstancesInput, ...func(*Options)) (*DescribeInstancesOutput, error)
163}
164
165var _ DescribeInstancesAPIClient = (*Client)(nil)
166
167// DescribeInstancesPaginatorOptions is the paginator options for DescribeInstances
168type DescribeInstancesPaginatorOptions struct {
169	// The maximum number of results to return. Use this parameter with NextToken to
170	// get results as a set of sequential pages.
171	Limit int32
172
173	// Set to true if pagination should stop if the service returns a pagination token
174	// that matches the most recent token provided to the service.
175	StopOnDuplicateToken bool
176}
177
178// DescribeInstancesPaginator is a paginator for DescribeInstances
179type DescribeInstancesPaginator struct {
180	options   DescribeInstancesPaginatorOptions
181	client    DescribeInstancesAPIClient
182	params    *DescribeInstancesInput
183	nextToken *string
184	firstPage bool
185}
186
187// NewDescribeInstancesPaginator returns a new DescribeInstancesPaginator
188func NewDescribeInstancesPaginator(client DescribeInstancesAPIClient, params *DescribeInstancesInput, optFns ...func(*DescribeInstancesPaginatorOptions)) *DescribeInstancesPaginator {
189	if params == nil {
190		params = &DescribeInstancesInput{}
191	}
192
193	options := DescribeInstancesPaginatorOptions{}
194	if params.Limit != nil {
195		options.Limit = *params.Limit
196	}
197
198	for _, fn := range optFns {
199		fn(&options)
200	}
201
202	return &DescribeInstancesPaginator{
203		options:   options,
204		client:    client,
205		params:    params,
206		firstPage: true,
207	}
208}
209
210// HasMorePages returns a boolean indicating whether more pages are available
211func (p *DescribeInstancesPaginator) HasMorePages() bool {
212	return p.firstPage || p.nextToken != nil
213}
214
215// NextPage retrieves the next DescribeInstances page.
216func (p *DescribeInstancesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeInstancesOutput, error) {
217	if !p.HasMorePages() {
218		return nil, fmt.Errorf("no more pages available")
219	}
220
221	params := *p.params
222	params.NextToken = p.nextToken
223
224	var limit *int32
225	if p.options.Limit > 0 {
226		limit = &p.options.Limit
227	}
228	params.Limit = limit
229
230	result, err := p.client.DescribeInstances(ctx, &params, optFns...)
231	if err != nil {
232		return nil, err
233	}
234	p.firstPage = false
235
236	prevToken := p.nextToken
237	p.nextToken = result.NextToken
238
239	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
240		p.nextToken = nil
241	}
242
243	return result, nil
244}
245
246func newServiceMetadataMiddleware_opDescribeInstances(region string) *awsmiddleware.RegisterServiceMetadata {
247	return &awsmiddleware.RegisterServiceMetadata{
248		Region:        region,
249		ServiceID:     ServiceID,
250		SigningName:   "gamelift",
251		OperationName: "DescribeInstances",
252	}
253}
254