1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package applicationautoscaling
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/applicationautoscaling/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Describes the Application Auto Scaling scaling policies for the specified
16// service namespace. You can filter the results using ResourceId,
17// ScalableDimension, and PolicyNames. For more information, see Target tracking
18// scaling policies
19// (https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-target-tracking.html)
20// and Step scaling policies
21// (https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-step-scaling-policies.html)
22// in the Application Auto Scaling User Guide.
23func (c *Client) DescribeScalingPolicies(ctx context.Context, params *DescribeScalingPoliciesInput, optFns ...func(*Options)) (*DescribeScalingPoliciesOutput, error) {
24	if params == nil {
25		params = &DescribeScalingPoliciesInput{}
26	}
27
28	result, metadata, err := c.invokeOperation(ctx, "DescribeScalingPolicies", params, optFns, addOperationDescribeScalingPoliciesMiddlewares)
29	if err != nil {
30		return nil, err
31	}
32
33	out := result.(*DescribeScalingPoliciesOutput)
34	out.ResultMetadata = metadata
35	return out, nil
36}
37
38type DescribeScalingPoliciesInput struct {
39
40	// The namespace of the AWS service that provides the resource. For a resource
41	// provided by your own application or service, use custom-resource instead.
42	//
43	// This member is required.
44	ServiceNamespace types.ServiceNamespace
45
46	// The maximum number of scalable targets. This value can be between 1 and 50. The
47	// default value is 50. If this parameter is used, the operation returns up to
48	// MaxResults results at a time, along with a NextToken value. To get the next set
49	// of results, include the NextToken value in a subsequent call. If this parameter
50	// is not used, the operation returns up to 50 results and a NextToken value, if
51	// applicable.
52	MaxResults *int32
53
54	// The token for the next set of results.
55	NextToken *string
56
57	// The names of the scaling policies to describe.
58	PolicyNames []string
59
60	// The identifier of the resource associated with the scaling policy. This string
61	// consists of the resource type and unique identifier.
62	//
63	// * ECS service - The
64	// resource type is service and the unique identifier is the cluster name and
65	// service name. Example: service/default/sample-webapp.
66	//
67	// * Spot Fleet request -
68	// The resource type is spot-fleet-request and the unique identifier is the Spot
69	// Fleet request ID. Example:
70	// spot-fleet-request/sfr-73fbd2ce-aa30-494c-8788-1cee4EXAMPLE.
71	//
72	// * EMR cluster -
73	// The resource type is instancegroup and the unique identifier is the cluster ID
74	// and instance group ID. Example:
75	// instancegroup/j-2EEZNYKUA1NTV/ig-1791Y4E1L8YI0.
76	//
77	// * AppStream 2.0 fleet - The
78	// resource type is fleet and the unique identifier is the fleet name. Example:
79	// fleet/sample-fleet.
80	//
81	// * DynamoDB table - The resource type is table and the
82	// unique identifier is the table name. Example: table/my-table.
83	//
84	// * DynamoDB global
85	// secondary index - The resource type is index and the unique identifier is the
86	// index name. Example: table/my-table/index/my-table-index.
87	//
88	// * Aurora DB cluster -
89	// The resource type is cluster and the unique identifier is the cluster name.
90	// Example: cluster:my-db-cluster.
91	//
92	// * Amazon SageMaker endpoint variant - The
93	// resource type is variant and the unique identifier is the resource ID. Example:
94	// endpoint/my-end-point/variant/KMeansClustering.
95	//
96	// * Custom resources are not
97	// supported with a resource type. This parameter must specify the OutputValue from
98	// the CloudFormation template stack used to access the resources. The unique
99	// identifier is defined by the service provider. More information is available in
100	// our GitHub repository
101	// (https://github.com/aws/aws-auto-scaling-custom-resource).
102	//
103	// * Amazon Comprehend
104	// document classification endpoint - The resource type and unique identifier are
105	// specified using the endpoint ARN. Example:
106	// arn:aws:comprehend:us-west-2:123456789012:document-classifier-endpoint/EXAMPLE.
107	//
108	// *
109	// Amazon Comprehend entity recognizer endpoint - The resource type and unique
110	// identifier are specified using the endpoint ARN. Example:
111	// arn:aws:comprehend:us-west-2:123456789012:entity-recognizer-endpoint/EXAMPLE.
112	//
113	// *
114	// Lambda provisioned concurrency - The resource type is function and the unique
115	// identifier is the function name with a function version or alias name suffix
116	// that is not $LATEST. Example: function:my-function:prod or
117	// function:my-function:1.
118	//
119	// * Amazon Keyspaces table - The resource type is table
120	// and the unique identifier is the table name. Example:
121	// keyspace/mykeyspace/table/mytable.
122	//
123	// * Amazon MSK cluster - The resource type and
124	// unique identifier are specified using the cluster ARN. Example:
125	// arn:aws:kafka:us-east-1:123456789012:cluster/demo-cluster-1/6357e0b2-0e6a-4b86-a0b4-70df934c2e31-5.
126	ResourceId *string
127
128	// The scalable dimension. This string consists of the service namespace, resource
129	// type, and scaling property. If you specify a scalable dimension, you must also
130	// specify a resource ID.
131	//
132	// * ecs:service:DesiredCount - The desired task count of
133	// an ECS service.
134	//
135	// * ec2:spot-fleet-request:TargetCapacity - The target capacity
136	// of a Spot Fleet request.
137	//
138	// * elasticmapreduce:instancegroup:InstanceCount - The
139	// instance count of an EMR Instance Group.
140	//
141	// * appstream:fleet:DesiredCapacity -
142	// The desired capacity of an AppStream 2.0 fleet.
143	//
144	// *
145	// dynamodb:table:ReadCapacityUnits - The provisioned read capacity for a DynamoDB
146	// table.
147	//
148	// * dynamodb:table:WriteCapacityUnits - The provisioned write capacity for
149	// a DynamoDB table.
150	//
151	// * dynamodb:index:ReadCapacityUnits - The provisioned read
152	// capacity for a DynamoDB global secondary index.
153	//
154	// *
155	// dynamodb:index:WriteCapacityUnits - The provisioned write capacity for a
156	// DynamoDB global secondary index.
157	//
158	// * rds:cluster:ReadReplicaCount - The count of
159	// Aurora Replicas in an Aurora DB cluster. Available for Aurora MySQL-compatible
160	// edition and Aurora PostgreSQL-compatible edition.
161	//
162	// *
163	// sagemaker:variant:DesiredInstanceCount - The number of EC2 instances for an
164	// Amazon SageMaker model endpoint variant.
165	//
166	// *
167	// custom-resource:ResourceType:Property - The scalable dimension for a custom
168	// resource provided by your own application or service.
169	//
170	// *
171	// comprehend:document-classifier-endpoint:DesiredInferenceUnits - The number of
172	// inference units for an Amazon Comprehend document classification endpoint.
173	//
174	// *
175	// comprehend:entity-recognizer-endpoint:DesiredInferenceUnits - The number of
176	// inference units for an Amazon Comprehend entity recognizer endpoint.
177	//
178	// *
179	// lambda:function:ProvisionedConcurrency - The provisioned concurrency for a
180	// Lambda function.
181	//
182	// * cassandra:table:ReadCapacityUnits - The provisioned read
183	// capacity for an Amazon Keyspaces table.
184	//
185	// * cassandra:table:WriteCapacityUnits -
186	// The provisioned write capacity for an Amazon Keyspaces table.
187	//
188	// *
189	// kafka:broker-storage:VolumeSize - The provisioned volume size (in GiB) for
190	// brokers in an Amazon MSK cluster.
191	ScalableDimension types.ScalableDimension
192}
193
194type DescribeScalingPoliciesOutput struct {
195
196	// The token required to get the next set of results. This value is null if there
197	// are no more results to return.
198	NextToken *string
199
200	// Information about the scaling policies.
201	ScalingPolicies []types.ScalingPolicy
202
203	// Metadata pertaining to the operation's result.
204	ResultMetadata middleware.Metadata
205}
206
207func addOperationDescribeScalingPoliciesMiddlewares(stack *middleware.Stack, options Options) (err error) {
208	err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribeScalingPolicies{}, middleware.After)
209	if err != nil {
210		return err
211	}
212	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribeScalingPolicies{}, middleware.After)
213	if err != nil {
214		return err
215	}
216	if err = addSetLoggerMiddleware(stack, options); err != nil {
217		return err
218	}
219	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
220		return err
221	}
222	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
223		return err
224	}
225	if err = addResolveEndpointMiddleware(stack, options); err != nil {
226		return err
227	}
228	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
229		return err
230	}
231	if err = addRetryMiddlewares(stack, options); err != nil {
232		return err
233	}
234	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
235		return err
236	}
237	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
238		return err
239	}
240	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
241		return err
242	}
243	if err = addClientUserAgent(stack); err != nil {
244		return err
245	}
246	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
247		return err
248	}
249	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
250		return err
251	}
252	if err = addOpDescribeScalingPoliciesValidationMiddleware(stack); err != nil {
253		return err
254	}
255	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeScalingPolicies(options.Region), middleware.Before); err != nil {
256		return err
257	}
258	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
259		return err
260	}
261	if err = addResponseErrorMiddleware(stack); err != nil {
262		return err
263	}
264	if err = addRequestResponseLogging(stack, options); err != nil {
265		return err
266	}
267	return nil
268}
269
270// DescribeScalingPoliciesAPIClient is a client that implements the
271// DescribeScalingPolicies operation.
272type DescribeScalingPoliciesAPIClient interface {
273	DescribeScalingPolicies(context.Context, *DescribeScalingPoliciesInput, ...func(*Options)) (*DescribeScalingPoliciesOutput, error)
274}
275
276var _ DescribeScalingPoliciesAPIClient = (*Client)(nil)
277
278// DescribeScalingPoliciesPaginatorOptions is the paginator options for
279// DescribeScalingPolicies
280type DescribeScalingPoliciesPaginatorOptions struct {
281	// The maximum number of scalable targets. This value can be between 1 and 50. The
282	// default value is 50. If this parameter is used, the operation returns up to
283	// MaxResults results at a time, along with a NextToken value. To get the next set
284	// of results, include the NextToken value in a subsequent call. If this parameter
285	// is not used, the operation returns up to 50 results and a NextToken value, if
286	// applicable.
287	Limit int32
288
289	// Set to true if pagination should stop if the service returns a pagination token
290	// that matches the most recent token provided to the service.
291	StopOnDuplicateToken bool
292}
293
294// DescribeScalingPoliciesPaginator is a paginator for DescribeScalingPolicies
295type DescribeScalingPoliciesPaginator struct {
296	options   DescribeScalingPoliciesPaginatorOptions
297	client    DescribeScalingPoliciesAPIClient
298	params    *DescribeScalingPoliciesInput
299	nextToken *string
300	firstPage bool
301}
302
303// NewDescribeScalingPoliciesPaginator returns a new
304// DescribeScalingPoliciesPaginator
305func NewDescribeScalingPoliciesPaginator(client DescribeScalingPoliciesAPIClient, params *DescribeScalingPoliciesInput, optFns ...func(*DescribeScalingPoliciesPaginatorOptions)) *DescribeScalingPoliciesPaginator {
306	if params == nil {
307		params = &DescribeScalingPoliciesInput{}
308	}
309
310	options := DescribeScalingPoliciesPaginatorOptions{}
311	if params.MaxResults != nil {
312		options.Limit = *params.MaxResults
313	}
314
315	for _, fn := range optFns {
316		fn(&options)
317	}
318
319	return &DescribeScalingPoliciesPaginator{
320		options:   options,
321		client:    client,
322		params:    params,
323		firstPage: true,
324	}
325}
326
327// HasMorePages returns a boolean indicating whether more pages are available
328func (p *DescribeScalingPoliciesPaginator) HasMorePages() bool {
329	return p.firstPage || p.nextToken != nil
330}
331
332// NextPage retrieves the next DescribeScalingPolicies page.
333func (p *DescribeScalingPoliciesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeScalingPoliciesOutput, error) {
334	if !p.HasMorePages() {
335		return nil, fmt.Errorf("no more pages available")
336	}
337
338	params := *p.params
339	params.NextToken = p.nextToken
340
341	var limit *int32
342	if p.options.Limit > 0 {
343		limit = &p.options.Limit
344	}
345	params.MaxResults = limit
346
347	result, err := p.client.DescribeScalingPolicies(ctx, &params, optFns...)
348	if err != nil {
349		return nil, err
350	}
351	p.firstPage = false
352
353	prevToken := p.nextToken
354	p.nextToken = result.NextToken
355
356	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
357		p.nextToken = nil
358	}
359
360	return result, nil
361}
362
363func newServiceMetadataMiddleware_opDescribeScalingPolicies(region string) *awsmiddleware.RegisterServiceMetadata {
364	return &awsmiddleware.RegisterServiceMetadata{
365		Region:        region,
366		ServiceID:     ServiceID,
367		SigningName:   "application-autoscaling",
368		OperationName: "DescribeScalingPolicies",
369	}
370}
371