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// Shuts down the specified instances. This operation is idempotent; if you 15// terminate an instance more than once, each call succeeds. If you specify 16// multiple instances and the request fails (for example, because of a single 17// incorrect instance ID), none of the instances are terminated. Terminated 18// instances remain visible after termination (for approximately one hour). By 19// default, Amazon EC2 deletes all EBS volumes that were attached when the instance 20// launched. Volumes attached after instance launch continue running. You can stop, 21// start, and terminate EBS-backed instances. You can only terminate instance 22// store-backed instances. What happens to an instance differs if you stop it or 23// terminate it. For example, when you stop an instance, the root device and any 24// other devices attached to the instance persist. When you terminate an instance, 25// any attached EBS volumes with the DeleteOnTermination block device mapping 26// parameter set to true are automatically deleted. For more information about the 27// differences between stopping and terminating instances, see Instance lifecycle 28// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-lifecycle.html) 29// in the Amazon EC2 User Guide. For more information about troubleshooting, see 30// Troubleshooting terminating your instance 31// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesShuttingDown.html) 32// in the Amazon EC2 User Guide. 33func (c *Client) TerminateInstances(ctx context.Context, params *TerminateInstancesInput, optFns ...func(*Options)) (*TerminateInstancesOutput, error) { 34 if params == nil { 35 params = &TerminateInstancesInput{} 36 } 37 38 result, metadata, err := c.invokeOperation(ctx, "TerminateInstances", params, optFns, addOperationTerminateInstancesMiddlewares) 39 if err != nil { 40 return nil, err 41 } 42 43 out := result.(*TerminateInstancesOutput) 44 out.ResultMetadata = metadata 45 return out, nil 46} 47 48type TerminateInstancesInput struct { 49 50 // The IDs of the instances. Constraints: Up to 1000 instance IDs. We recommend 51 // breaking up this request into smaller batches. 52 // 53 // This member is required. 54 InstanceIds []string 55 56 // Checks whether you have the required permissions for the action, without 57 // actually making the request, and provides an error response. If you have the 58 // required permissions, the error response is DryRunOperation. Otherwise, it is 59 // UnauthorizedOperation. 60 DryRun bool 61} 62 63type TerminateInstancesOutput struct { 64 65 // Information about the terminated instances. 66 TerminatingInstances []types.InstanceStateChange 67 68 // Metadata pertaining to the operation's result. 69 ResultMetadata middleware.Metadata 70} 71 72func addOperationTerminateInstancesMiddlewares(stack *middleware.Stack, options Options) (err error) { 73 err = stack.Serialize.Add(&awsEc2query_serializeOpTerminateInstances{}, middleware.After) 74 if err != nil { 75 return err 76 } 77 err = stack.Deserialize.Add(&awsEc2query_deserializeOpTerminateInstances{}, middleware.After) 78 if err != nil { 79 return err 80 } 81 if err = addSetLoggerMiddleware(stack, options); err != nil { 82 return err 83 } 84 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 85 return err 86 } 87 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 88 return err 89 } 90 if err = addResolveEndpointMiddleware(stack, options); err != nil { 91 return err 92 } 93 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 94 return err 95 } 96 if err = addRetryMiddlewares(stack, options); err != nil { 97 return err 98 } 99 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 100 return err 101 } 102 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 103 return err 104 } 105 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 106 return err 107 } 108 if err = addClientUserAgent(stack); err != nil { 109 return err 110 } 111 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 112 return err 113 } 114 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 115 return err 116 } 117 if err = addOpTerminateInstancesValidationMiddleware(stack); err != nil { 118 return err 119 } 120 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opTerminateInstances(options.Region), middleware.Before); err != nil { 121 return err 122 } 123 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 124 return err 125 } 126 if err = addResponseErrorMiddleware(stack); err != nil { 127 return err 128 } 129 if err = addRequestResponseLogging(stack, options); err != nil { 130 return err 131 } 132 return nil 133} 134 135func newServiceMetadataMiddleware_opTerminateInstances(region string) *awsmiddleware.RegisterServiceMetadata { 136 return &awsmiddleware.RegisterServiceMetadata{ 137 Region: region, 138 ServiceID: ServiceID, 139 SigningName: "ec2", 140 OperationName: "TerminateInstances", 141 } 142} 143