1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package ecs 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/ecs/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Returns a list of container instances in a specified cluster. You can filter the 16// results of a ListContainerInstances operation with cluster query language 17// statements inside the filter parameter. For more information, see Cluster Query 18// Language 19// (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html) 20// in the Amazon Elastic Container Service Developer Guide. 21func (c *Client) ListContainerInstances(ctx context.Context, params *ListContainerInstancesInput, optFns ...func(*Options)) (*ListContainerInstancesOutput, error) { 22 if params == nil { 23 params = &ListContainerInstancesInput{} 24 } 25 26 result, metadata, err := c.invokeOperation(ctx, "ListContainerInstances", params, optFns, addOperationListContainerInstancesMiddlewares) 27 if err != nil { 28 return nil, err 29 } 30 31 out := result.(*ListContainerInstancesOutput) 32 out.ResultMetadata = metadata 33 return out, nil 34} 35 36type ListContainerInstancesInput struct { 37 38 // The short name or full Amazon Resource Name (ARN) of the cluster that hosts the 39 // container instances to list. If you do not specify a cluster, the default 40 // cluster is assumed. 41 Cluster *string 42 43 // You can filter the results of a ListContainerInstances operation with cluster 44 // query language statements. For more information, see Cluster Query Language 45 // (https://docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html) 46 // in the Amazon Elastic Container Service Developer Guide. 47 Filter *string 48 49 // The maximum number of container instance results returned by 50 // ListContainerInstances in paginated output. When this parameter is used, 51 // ListContainerInstances only returns maxResults results in a single page along 52 // with a nextToken response element. The remaining results of the initial request 53 // can be seen by sending another ListContainerInstances request with the returned 54 // nextToken value. This value can be between 1 and 100. If this parameter is not 55 // used, then ListContainerInstances returns up to 100 results and a nextToken 56 // value if applicable. 57 MaxResults *int32 58 59 // The nextToken value returned from a ListContainerInstances request indicating 60 // that more results are available to fulfill the request and further calls will be 61 // needed. If maxResults was provided, it is possible the number of results to be 62 // fewer than maxResults. This token should be treated as an opaque identifier that 63 // is only used to retrieve the next items in a list and not for other programmatic 64 // purposes. 65 NextToken *string 66 67 // Filters the container instances by status. For example, if you specify the 68 // DRAINING status, the results include only container instances that have been set 69 // to DRAINING using UpdateContainerInstancesState. If you do not specify this 70 // parameter, the default is to include container instances set to all states other 71 // than INACTIVE. 72 Status types.ContainerInstanceStatus 73} 74 75type ListContainerInstancesOutput struct { 76 77 // The list of container instances with full ARN entries for each container 78 // instance associated with the specified cluster. 79 ContainerInstanceArns []string 80 81 // The nextToken value to include in a future ListContainerInstances request. When 82 // the results of a ListContainerInstances request exceed maxResults, this value 83 // can be used to retrieve the next page of results. This value is null when there 84 // are no more results to return. 85 NextToken *string 86 87 // Metadata pertaining to the operation's result. 88 ResultMetadata middleware.Metadata 89} 90 91func addOperationListContainerInstancesMiddlewares(stack *middleware.Stack, options Options) (err error) { 92 err = stack.Serialize.Add(&awsAwsjson11_serializeOpListContainerInstances{}, middleware.After) 93 if err != nil { 94 return err 95 } 96 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpListContainerInstances{}, middleware.After) 97 if err != nil { 98 return err 99 } 100 if err = addSetLoggerMiddleware(stack, options); err != nil { 101 return err 102 } 103 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 104 return err 105 } 106 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 107 return err 108 } 109 if err = addResolveEndpointMiddleware(stack, options); err != nil { 110 return err 111 } 112 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 113 return err 114 } 115 if err = addRetryMiddlewares(stack, options); err != nil { 116 return err 117 } 118 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 119 return err 120 } 121 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 122 return err 123 } 124 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 125 return err 126 } 127 if err = addClientUserAgent(stack); err != nil { 128 return err 129 } 130 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 131 return err 132 } 133 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 134 return err 135 } 136 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListContainerInstances(options.Region), middleware.Before); err != nil { 137 return err 138 } 139 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 140 return err 141 } 142 if err = addResponseErrorMiddleware(stack); err != nil { 143 return err 144 } 145 if err = addRequestResponseLogging(stack, options); err != nil { 146 return err 147 } 148 return nil 149} 150 151// ListContainerInstancesAPIClient is a client that implements the 152// ListContainerInstances operation. 153type ListContainerInstancesAPIClient interface { 154 ListContainerInstances(context.Context, *ListContainerInstancesInput, ...func(*Options)) (*ListContainerInstancesOutput, error) 155} 156 157var _ ListContainerInstancesAPIClient = (*Client)(nil) 158 159// ListContainerInstancesPaginatorOptions is the paginator options for 160// ListContainerInstances 161type ListContainerInstancesPaginatorOptions struct { 162 // The maximum number of container instance results returned by 163 // ListContainerInstances in paginated output. When this parameter is used, 164 // ListContainerInstances only returns maxResults results in a single page along 165 // with a nextToken response element. The remaining results of the initial request 166 // can be seen by sending another ListContainerInstances request with the returned 167 // nextToken value. This value can be between 1 and 100. If this parameter is not 168 // used, then ListContainerInstances returns up to 100 results and a nextToken 169 // value if applicable. 170 Limit int32 171 172 // Set to true if pagination should stop if the service returns a pagination token 173 // that matches the most recent token provided to the service. 174 StopOnDuplicateToken bool 175} 176 177// ListContainerInstancesPaginator is a paginator for ListContainerInstances 178type ListContainerInstancesPaginator struct { 179 options ListContainerInstancesPaginatorOptions 180 client ListContainerInstancesAPIClient 181 params *ListContainerInstancesInput 182 nextToken *string 183 firstPage bool 184} 185 186// NewListContainerInstancesPaginator returns a new ListContainerInstancesPaginator 187func NewListContainerInstancesPaginator(client ListContainerInstancesAPIClient, params *ListContainerInstancesInput, optFns ...func(*ListContainerInstancesPaginatorOptions)) *ListContainerInstancesPaginator { 188 if params == nil { 189 params = &ListContainerInstancesInput{} 190 } 191 192 options := ListContainerInstancesPaginatorOptions{} 193 if params.MaxResults != nil { 194 options.Limit = *params.MaxResults 195 } 196 197 for _, fn := range optFns { 198 fn(&options) 199 } 200 201 return &ListContainerInstancesPaginator{ 202 options: options, 203 client: client, 204 params: params, 205 firstPage: true, 206 } 207} 208 209// HasMorePages returns a boolean indicating whether more pages are available 210func (p *ListContainerInstancesPaginator) HasMorePages() bool { 211 return p.firstPage || p.nextToken != nil 212} 213 214// NextPage retrieves the next ListContainerInstances page. 215func (p *ListContainerInstancesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListContainerInstancesOutput, error) { 216 if !p.HasMorePages() { 217 return nil, fmt.Errorf("no more pages available") 218 } 219 220 params := *p.params 221 params.NextToken = p.nextToken 222 223 var limit *int32 224 if p.options.Limit > 0 { 225 limit = &p.options.Limit 226 } 227 params.MaxResults = limit 228 229 result, err := p.client.ListContainerInstances(ctx, ¶ms, optFns...) 230 if err != nil { 231 return nil, err 232 } 233 p.firstPage = false 234 235 prevToken := p.nextToken 236 p.nextToken = result.NextToken 237 238 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 239 p.nextToken = nil 240 } 241 242 return result, nil 243} 244 245func newServiceMetadataMiddleware_opListContainerInstances(region string) *awsmiddleware.RegisterServiceMetadata { 246 return &awsmiddleware.RegisterServiceMetadata{ 247 Region: region, 248 ServiceID: ServiceID, 249 SigningName: "ecs", 250 OperationName: "ListContainerInstances", 251 } 252} 253