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) 13 14// Stops an Amazon EBS-backed instance. You can use the Stop action to hibernate an 15// instance if the instance is enabled for hibernation 16// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Hibernate.html#enabling-hibernation) 17// and it meets the hibernation prerequisites 18// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Hibernate.html#hibernating-prerequisites). 19// For more information, see Hibernate your instance 20// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Hibernate.html) in the 21// Amazon EC2 User Guide. We don't charge usage for a stopped instance, or data 22// transfer fees; however, your root partition Amazon EBS volume remains and 23// continues to persist your data, and you are charged for Amazon EBS volume usage. 24// Every time you start your Windows instance, Amazon EC2 charges you for a full 25// instance hour. If you stop and restart your Windows instance, a new instance 26// hour begins and Amazon EC2 charges you for another full instance hour even if 27// you are still within the same 60-minute period when it was stopped. Every time 28// you start your Linux instance, Amazon EC2 charges a one-minute minimum for 29// instance usage, and thereafter charges per second for instance usage. You can't 30// stop or hibernate instance store-backed instances. You can't use the Stop action 31// to hibernate Spot Instances, but you can specify that Amazon EC2 should 32// hibernate Spot Instances when they are interrupted. For more information, see 33// Hibernating interrupted Spot Instances 34// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/spot-interruptions.html#hibernate-spot-instances) 35// in the Amazon EC2 User Guide. When you stop or hibernate an instance, we shut it 36// down. You can restart your instance at any time. Before stopping or hibernating 37// an instance, make sure it is in a state from which it can be restarted. Stopping 38// an instance does not preserve data stored in RAM, but hibernating an instance 39// does preserve data stored in RAM. If an instance cannot hibernate successfully, 40// a normal shutdown occurs. Stopping and hibernating an instance is different to 41// rebooting or terminating it. For example, when you stop or hibernate an 42// instance, the root device and any other devices attached to the instance 43// persist. When you terminate an instance, the root device and any other devices 44// attached during the instance launch are automatically deleted. For more 45// information about the differences between rebooting, stopping, hibernating, and 46// terminating instances, see Instance lifecycle 47// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-lifecycle.html) 48// in the Amazon EC2 User Guide. When you stop an instance, we attempt to shut it 49// down forcibly after a short while. If your instance appears stuck in the 50// stopping state after a period of time, there may be an issue with the underlying 51// host computer. For more information, see Troubleshooting stopping your instance 52// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesStopping.html) 53// in the Amazon EC2 User Guide. 54func (c *Client) StopInstances(ctx context.Context, params *StopInstancesInput, optFns ...func(*Options)) (*StopInstancesOutput, error) { 55 if params == nil { 56 params = &StopInstancesInput{} 57 } 58 59 result, metadata, err := c.invokeOperation(ctx, "StopInstances", params, optFns, addOperationStopInstancesMiddlewares) 60 if err != nil { 61 return nil, err 62 } 63 64 out := result.(*StopInstancesOutput) 65 out.ResultMetadata = metadata 66 return out, nil 67} 68 69type StopInstancesInput struct { 70 71 // The IDs of the instances. 72 // 73 // This member is required. 74 InstanceIds []string 75 76 // Checks whether you have the required permissions for the action, without 77 // actually making the request, and provides an error response. If you have the 78 // required permissions, the error response is DryRunOperation. Otherwise, it is 79 // UnauthorizedOperation. 80 DryRun bool 81 82 // Forces the instances to stop. The instances do not have an opportunity to flush 83 // file system caches or file system metadata. If you use this option, you must 84 // perform file system check and repair procedures. This option is not recommended 85 // for Windows instances. Default: false 86 Force bool 87 88 // Hibernates the instance if the instance was enabled for hibernation at launch. 89 // If the instance cannot hibernate successfully, a normal shutdown occurs. For 90 // more information, see Hibernate your instance 91 // (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Hibernate.html) in the 92 // Amazon EC2 User Guide. Default: false 93 Hibernate bool 94} 95 96type StopInstancesOutput struct { 97 98 // Information about the stopped instances. 99 StoppingInstances []types.InstanceStateChange 100 101 // Metadata pertaining to the operation's result. 102 ResultMetadata middleware.Metadata 103} 104 105func addOperationStopInstancesMiddlewares(stack *middleware.Stack, options Options) (err error) { 106 err = stack.Serialize.Add(&awsEc2query_serializeOpStopInstances{}, middleware.After) 107 if err != nil { 108 return err 109 } 110 err = stack.Deserialize.Add(&awsEc2query_deserializeOpStopInstances{}, middleware.After) 111 if err != nil { 112 return err 113 } 114 if err = addSetLoggerMiddleware(stack, options); err != nil { 115 return err 116 } 117 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 118 return err 119 } 120 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 121 return err 122 } 123 if err = addResolveEndpointMiddleware(stack, options); err != nil { 124 return err 125 } 126 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 127 return err 128 } 129 if err = addRetryMiddlewares(stack, options); err != nil { 130 return err 131 } 132 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 133 return err 134 } 135 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 136 return err 137 } 138 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 139 return err 140 } 141 if err = addClientUserAgent(stack); err != nil { 142 return err 143 } 144 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 145 return err 146 } 147 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 148 return err 149 } 150 if err = addOpStopInstancesValidationMiddleware(stack); err != nil { 151 return err 152 } 153 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opStopInstances(options.Region), middleware.Before); err != nil { 154 return err 155 } 156 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 157 return err 158 } 159 if err = addResponseErrorMiddleware(stack); err != nil { 160 return err 161 } 162 if err = addRequestResponseLogging(stack, options); err != nil { 163 return err 164 } 165 return nil 166} 167 168func newServiceMetadataMiddleware_opStopInstances(region string) *awsmiddleware.RegisterServiceMetadata { 169 return &awsmiddleware.RegisterServiceMetadata{ 170 Region: region, 171 ServiceID: ServiceID, 172 SigningName: "ec2", 173 OperationName: "StopInstances", 174 } 175} 176