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// Purchases a Reserved Instance for use with your account. With Reserved
16// Instances, you pay a lower hourly rate compared to On-Demand instance pricing.
17// Use DescribeReservedInstancesOfferings to get a list of Reserved Instance
18// offerings that match your specifications. After you've purchased a Reserved
19// Instance, you can check for your new Reserved Instance with
20// DescribeReservedInstances. To queue a purchase for a future date and time,
21// specify a purchase time. If you do not specify a purchase time, the default is
22// the current time. For more information, see Reserved Instances
23// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts-on-demand-reserved-instances.html)
24// and Reserved Instance Marketplace
25// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ri-market-general.html) in
26// the Amazon EC2 User Guide.
27func (c *Client) PurchaseReservedInstancesOffering(ctx context.Context, params *PurchaseReservedInstancesOfferingInput, optFns ...func(*Options)) (*PurchaseReservedInstancesOfferingOutput, error) {
28	if params == nil {
29		params = &PurchaseReservedInstancesOfferingInput{}
30	}
31
32	result, metadata, err := c.invokeOperation(ctx, "PurchaseReservedInstancesOffering", params, optFns, c.addOperationPurchaseReservedInstancesOfferingMiddlewares)
33	if err != nil {
34		return nil, err
35	}
36
37	out := result.(*PurchaseReservedInstancesOfferingOutput)
38	out.ResultMetadata = metadata
39	return out, nil
40}
41
42// Contains the parameters for PurchaseReservedInstancesOffering.
43type PurchaseReservedInstancesOfferingInput struct {
44
45	// The number of Reserved Instances to purchase.
46	//
47	// This member is required.
48	InstanceCount *int32
49
50	// The ID of the Reserved Instance offering to purchase.
51	//
52	// This member is required.
53	ReservedInstancesOfferingId *string
54
55	// Checks whether you have the required permissions for the action, without
56	// actually making the request, and provides an error response. If you have the
57	// required permissions, the error response is DryRunOperation. Otherwise, it is
58	// UnauthorizedOperation.
59	DryRun *bool
60
61	// Specified for Reserved Instance Marketplace offerings to limit the total order
62	// and ensure that the Reserved Instances are not purchased at unexpected prices.
63	LimitPrice *types.ReservedInstanceLimitPrice
64
65	// The time at which to purchase the Reserved Instance, in UTC format (for example,
66	// YYYY-MM-DDTHH:MM:SSZ).
67	PurchaseTime *time.Time
68
69	noSmithyDocumentSerde
70}
71
72// Contains the output of PurchaseReservedInstancesOffering.
73type PurchaseReservedInstancesOfferingOutput struct {
74
75	// The IDs of the purchased Reserved Instances. If your purchase crosses into a
76	// discounted pricing tier, the final Reserved Instances IDs might change. For more
77	// information, see Crossing pricing tiers
78	// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts-reserved-instances-application.html#crossing-pricing-tiers)
79	// in the Amazon Elastic Compute Cloud User Guide.
80	ReservedInstancesId *string
81
82	// Metadata pertaining to the operation's result.
83	ResultMetadata middleware.Metadata
84
85	noSmithyDocumentSerde
86}
87
88func (c *Client) addOperationPurchaseReservedInstancesOfferingMiddlewares(stack *middleware.Stack, options Options) (err error) {
89	err = stack.Serialize.Add(&awsEc2query_serializeOpPurchaseReservedInstancesOffering{}, middleware.After)
90	if err != nil {
91		return err
92	}
93	err = stack.Deserialize.Add(&awsEc2query_deserializeOpPurchaseReservedInstancesOffering{}, middleware.After)
94	if err != nil {
95		return err
96	}
97	if err = addSetLoggerMiddleware(stack, options); err != nil {
98		return err
99	}
100	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
101		return err
102	}
103	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
104		return err
105	}
106	if err = addResolveEndpointMiddleware(stack, options); err != nil {
107		return err
108	}
109	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
110		return err
111	}
112	if err = addRetryMiddlewares(stack, options); err != nil {
113		return err
114	}
115	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
116		return err
117	}
118	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
119		return err
120	}
121	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
122		return err
123	}
124	if err = addClientUserAgent(stack); err != nil {
125		return err
126	}
127	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
128		return err
129	}
130	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
131		return err
132	}
133	if err = addOpPurchaseReservedInstancesOfferingValidationMiddleware(stack); err != nil {
134		return err
135	}
136	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opPurchaseReservedInstancesOffering(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
151func newServiceMetadataMiddleware_opPurchaseReservedInstancesOffering(region string) *awsmiddleware.RegisterServiceMetadata {
152	return &awsmiddleware.RegisterServiceMetadata{
153		Region:        region,
154		ServiceID:     ServiceID,
155		SigningName:   "ec2",
156		OperationName: "PurchaseReservedInstancesOffering",
157	}
158}
159