api_op_StopInstance.go raw
1 // Code generated by smithy-go-codegen DO NOT EDIT.
2
3 package lightsail
4
5 import (
6 "context"
7 "fmt"
8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9 "github.com/aws/aws-sdk-go-v2/service/lightsail/types"
10 "github.com/aws/smithy-go/middleware"
11 smithyhttp "github.com/aws/smithy-go/transport/http"
12 )
13
14 // Stops a specific Amazon Lightsail instance that is currently running.
15 //
16 // When you start a stopped instance, Lightsail assigns a new public IP address to
17 // the instance. To use the same IP address after stopping and starting an
18 // instance, create a static IP address and attach it to the instance. For more
19 // information, see the [Amazon Lightsail Developer Guide].
20 //
21 // The stop instance operation supports tag-based access control via resource tags
22 // applied to the resource identified by instance name . For more information, see
23 // the [Amazon Lightsail Developer Guide].
24 //
25 // [Amazon Lightsail Developer Guide]: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-controlling-access-using-tags
26 func (c *Client) StopInstance(ctx context.Context, params *StopInstanceInput, optFns ...func(*Options)) (*StopInstanceOutput, error) {
27 if params == nil {
28 params = &StopInstanceInput{}
29 }
30
31 result, metadata, err := c.invokeOperation(ctx, "StopInstance", params, optFns, c.addOperationStopInstanceMiddlewares)
32 if err != nil {
33 return nil, err
34 }
35
36 out := result.(*StopInstanceOutput)
37 out.ResultMetadata = metadata
38 return out, nil
39 }
40
41 type StopInstanceInput struct {
42
43 // The name of the instance (a virtual private server) to stop.
44 //
45 // This member is required.
46 InstanceName *string
47
48 // When set to True , forces a Lightsail instance that is stuck in a stopping
49 // state to stop.
50 //
51 // Only use the force parameter if your instance is stuck in the stopping state.
52 // In any other state, your instance should stop normally without adding this
53 // parameter to your API request.
54 Force *bool
55
56 noSmithyDocumentSerde
57 }
58
59 type StopInstanceOutput struct {
60
61 // An array of objects that describe the result of the action, such as the status
62 // of the request, the timestamp of the request, and the resources affected by the
63 // request.
64 Operations []types.Operation
65
66 // Metadata pertaining to the operation's result.
67 ResultMetadata middleware.Metadata
68
69 noSmithyDocumentSerde
70 }
71
72 func (c *Client) addOperationStopInstanceMiddlewares(stack *middleware.Stack, options Options) (err error) {
73 if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
74 return err
75 }
76 err = stack.Serialize.Add(&awsAwsjson11_serializeOpStopInstance{}, middleware.After)
77 if err != nil {
78 return err
79 }
80 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpStopInstance{}, middleware.After)
81 if err != nil {
82 return err
83 }
84 if err := addProtocolFinalizerMiddlewares(stack, options, "StopInstance"); err != nil {
85 return fmt.Errorf("add protocol finalizers: %v", err)
86 }
87
88 if err = addlegacyEndpointContextSetter(stack, options); err != nil {
89 return err
90 }
91 if err = addSetLoggerMiddleware(stack, options); err != nil {
92 return err
93 }
94 if err = addClientRequestID(stack); err != nil {
95 return err
96 }
97 if err = addComputeContentLength(stack); err != nil {
98 return err
99 }
100 if err = addResolveEndpointMiddleware(stack, options); err != nil {
101 return err
102 }
103 if err = addComputePayloadSHA256(stack); err != nil {
104 return err
105 }
106 if err = addRetry(stack, options); err != nil {
107 return err
108 }
109 if err = addRawResponseToMetadata(stack); err != nil {
110 return err
111 }
112 if err = addRecordResponseTiming(stack); err != nil {
113 return err
114 }
115 if err = addSpanRetryLoop(stack, options); err != nil {
116 return err
117 }
118 if err = addClientUserAgent(stack, options); err != nil {
119 return err
120 }
121 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
122 return err
123 }
124 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
125 return err
126 }
127 if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
128 return err
129 }
130 if err = addTimeOffsetBuild(stack, c); err != nil {
131 return err
132 }
133 if err = addUserAgentRetryMode(stack, options); err != nil {
134 return err
135 }
136 if err = addCredentialSource(stack, options); err != nil {
137 return err
138 }
139 if err = addOpStopInstanceValidationMiddleware(stack); err != nil {
140 return err
141 }
142 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opStopInstance(options.Region), middleware.Before); err != nil {
143 return err
144 }
145 if err = addRecursionDetection(stack); err != nil {
146 return err
147 }
148 if err = addRequestIDRetrieverMiddleware(stack); err != nil {
149 return err
150 }
151 if err = addResponseErrorMiddleware(stack); err != nil {
152 return err
153 }
154 if err = addRequestResponseLogging(stack, options); err != nil {
155 return err
156 }
157 if err = addDisableHTTPSMiddleware(stack, options); err != nil {
158 return err
159 }
160 if err = addInterceptBeforeRetryLoop(stack, options); err != nil {
161 return err
162 }
163 if err = addInterceptAttempt(stack, options); err != nil {
164 return err
165 }
166 if err = addInterceptors(stack, options); err != nil {
167 return err
168 }
169 return nil
170 }
171
172 func newServiceMetadataMiddleware_opStopInstance(region string) *awsmiddleware.RegisterServiceMetadata {
173 return &awsmiddleware.RegisterServiceMetadata{
174 Region: region,
175 ServiceID: ServiceID,
176 OperationName: "StopInstance",
177 }
178 }
179