1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package ec2 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/ec2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13 "time" 14) 15 16// Describes the Spot price history. For more information, see Spot Instance 17// pricing history 18// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances-history.html) 19// in the Amazon EC2 User Guide for Linux Instances. When you specify a start and 20// end time, this operation returns the prices of the instance types within the 21// time range that you specified and the time when the price changed. The price is 22// valid within the time period that you specified; the response merely indicates 23// the last time that the price changed. 24func (c *Client) DescribeSpotPriceHistory(ctx context.Context, params *DescribeSpotPriceHistoryInput, optFns ...func(*Options)) (*DescribeSpotPriceHistoryOutput, error) { 25 if params == nil { 26 params = &DescribeSpotPriceHistoryInput{} 27 } 28 29 result, metadata, err := c.invokeOperation(ctx, "DescribeSpotPriceHistory", params, optFns, addOperationDescribeSpotPriceHistoryMiddlewares) 30 if err != nil { 31 return nil, err 32 } 33 34 out := result.(*DescribeSpotPriceHistoryOutput) 35 out.ResultMetadata = metadata 36 return out, nil 37} 38 39// Contains the parameters for DescribeSpotPriceHistory. 40type DescribeSpotPriceHistoryInput struct { 41 42 // Filters the results by the specified Availability Zone. 43 AvailabilityZone *string 44 45 // Checks whether you have the required permissions for the action, without 46 // actually making the request, and provides an error response. If you have the 47 // required permissions, the error response is DryRunOperation. Otherwise, it is 48 // UnauthorizedOperation. 49 DryRun bool 50 51 // The date and time, up to the current date, from which to stop retrieving the 52 // price history data, in UTC format (for example, YYYY-MM-DDTHH:MM:SSZ). 53 EndTime *time.Time 54 55 // One or more filters. 56 // 57 // * availability-zone - The Availability Zone for which 58 // prices should be returned. 59 // 60 // * instance-type - The type of instance (for example, 61 // m3.medium). 62 // 63 // * product-description - The product description for the Spot price 64 // (Linux/UNIX | Red Hat Enterprise Linux | SUSE Linux | Windows | Linux/UNIX 65 // (Amazon VPC) | Red Hat Enterprise Linux (Amazon VPC) | SUSE Linux (Amazon VPC) | 66 // Windows (Amazon VPC)). 67 // 68 // * spot-price - The Spot price. The value must match 69 // exactly (or use wildcards; greater than or less than comparison is not 70 // supported). 71 // 72 // * timestamp - The time stamp of the Spot price history, in UTC 73 // format (for example, YYYY-MM-DDTHH:MM:SSZ). You can use wildcards (* and ?). 74 // Greater than or less than comparison is not supported. 75 Filters []types.Filter 76 77 // Filters the results by the specified instance types. 78 InstanceTypes []types.InstanceType 79 80 // The maximum number of results to return in a single call. Specify a value 81 // between 1 and 1000. The default value is 1000. To retrieve the remaining 82 // results, make another call with the returned NextToken value. 83 MaxResults int32 84 85 // The token for the next set of results. 86 NextToken *string 87 88 // Filters the results by the specified basic product descriptions. 89 ProductDescriptions []string 90 91 // The date and time, up to the past 90 days, from which to start retrieving the 92 // price history data, in UTC format (for example, YYYY-MM-DDTHH:MM:SSZ). 93 StartTime *time.Time 94} 95 96// Contains the output of DescribeSpotPriceHistory. 97type DescribeSpotPriceHistoryOutput struct { 98 99 // The token required to retrieve the next set of results. This value is null or an 100 // empty string when there are no more results to return. 101 NextToken *string 102 103 // The historical Spot prices. 104 SpotPriceHistory []types.SpotPrice 105 106 // Metadata pertaining to the operation's result. 107 ResultMetadata middleware.Metadata 108} 109 110func addOperationDescribeSpotPriceHistoryMiddlewares(stack *middleware.Stack, options Options) (err error) { 111 err = stack.Serialize.Add(&awsEc2query_serializeOpDescribeSpotPriceHistory{}, middleware.After) 112 if err != nil { 113 return err 114 } 115 err = stack.Deserialize.Add(&awsEc2query_deserializeOpDescribeSpotPriceHistory{}, middleware.After) 116 if err != nil { 117 return err 118 } 119 if err = addSetLoggerMiddleware(stack, options); err != nil { 120 return err 121 } 122 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 123 return err 124 } 125 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 126 return err 127 } 128 if err = addResolveEndpointMiddleware(stack, options); err != nil { 129 return err 130 } 131 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 132 return err 133 } 134 if err = addRetryMiddlewares(stack, options); err != nil { 135 return err 136 } 137 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 138 return err 139 } 140 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 141 return err 142 } 143 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 144 return err 145 } 146 if err = addClientUserAgent(stack); err != nil { 147 return err 148 } 149 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 150 return err 151 } 152 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 153 return err 154 } 155 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeSpotPriceHistory(options.Region), middleware.Before); err != nil { 156 return err 157 } 158 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 159 return err 160 } 161 if err = addResponseErrorMiddleware(stack); err != nil { 162 return err 163 } 164 if err = addRequestResponseLogging(stack, options); err != nil { 165 return err 166 } 167 return nil 168} 169 170// DescribeSpotPriceHistoryAPIClient is a client that implements the 171// DescribeSpotPriceHistory operation. 172type DescribeSpotPriceHistoryAPIClient interface { 173 DescribeSpotPriceHistory(context.Context, *DescribeSpotPriceHistoryInput, ...func(*Options)) (*DescribeSpotPriceHistoryOutput, error) 174} 175 176var _ DescribeSpotPriceHistoryAPIClient = (*Client)(nil) 177 178// DescribeSpotPriceHistoryPaginatorOptions is the paginator options for 179// DescribeSpotPriceHistory 180type DescribeSpotPriceHistoryPaginatorOptions struct { 181 // The maximum number of results to return in a single call. Specify a value 182 // between 1 and 1000. The default value is 1000. To retrieve the remaining 183 // results, make another call with the returned NextToken value. 184 Limit int32 185 186 // Set to true if pagination should stop if the service returns a pagination token 187 // that matches the most recent token provided to the service. 188 StopOnDuplicateToken bool 189} 190 191// DescribeSpotPriceHistoryPaginator is a paginator for DescribeSpotPriceHistory 192type DescribeSpotPriceHistoryPaginator struct { 193 options DescribeSpotPriceHistoryPaginatorOptions 194 client DescribeSpotPriceHistoryAPIClient 195 params *DescribeSpotPriceHistoryInput 196 nextToken *string 197 firstPage bool 198} 199 200// NewDescribeSpotPriceHistoryPaginator returns a new 201// DescribeSpotPriceHistoryPaginator 202func NewDescribeSpotPriceHistoryPaginator(client DescribeSpotPriceHistoryAPIClient, params *DescribeSpotPriceHistoryInput, optFns ...func(*DescribeSpotPriceHistoryPaginatorOptions)) *DescribeSpotPriceHistoryPaginator { 203 options := DescribeSpotPriceHistoryPaginatorOptions{} 204 if params.MaxResults != 0 { 205 options.Limit = params.MaxResults 206 } 207 208 for _, fn := range optFns { 209 fn(&options) 210 } 211 212 if params == nil { 213 params = &DescribeSpotPriceHistoryInput{} 214 } 215 216 return &DescribeSpotPriceHistoryPaginator{ 217 options: options, 218 client: client, 219 params: params, 220 firstPage: true, 221 } 222} 223 224// HasMorePages returns a boolean indicating whether more pages are available 225func (p *DescribeSpotPriceHistoryPaginator) HasMorePages() bool { 226 return p.firstPage || p.nextToken != nil 227} 228 229// NextPage retrieves the next DescribeSpotPriceHistory page. 230func (p *DescribeSpotPriceHistoryPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeSpotPriceHistoryOutput, error) { 231 if !p.HasMorePages() { 232 return nil, fmt.Errorf("no more pages available") 233 } 234 235 params := *p.params 236 params.NextToken = p.nextToken 237 238 params.MaxResults = p.options.Limit 239 240 result, err := p.client.DescribeSpotPriceHistory(ctx, ¶ms, optFns...) 241 if err != nil { 242 return nil, err 243 } 244 p.firstPage = false 245 246 prevToken := p.nextToken 247 p.nextToken = result.NextToken 248 249 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 250 p.nextToken = nil 251 } 252 253 return result, nil 254} 255 256func newServiceMetadataMiddleware_opDescribeSpotPriceHistory(region string) *awsmiddleware.RegisterServiceMetadata { 257 return &awsmiddleware.RegisterServiceMetadata{ 258 Region: region, 259 ServiceID: ServiceID, 260 SigningName: "ec2", 261 OperationName: "DescribeSpotPriceHistory", 262 } 263} 264