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// Attaches an EBS volume to a running or stopped instance and exposes it to the 16// instance with the specified device name. Encrypted EBS volumes must be attached 17// to instances that support Amazon EBS encryption. For more information, see 18// Amazon EBS encryption 19// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html) in the 20// Amazon Elastic Compute Cloud User Guide. After you attach an EBS volume, you 21// must make it available. For more information, see Making an EBS volume available 22// for use 23// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html). If 24// a volume has an AWS Marketplace product code: 25// 26// * The volume can be attached only 27// to a stopped instance. 28// 29// * AWS Marketplace product codes are copied from the 30// volume to the instance. 31// 32// * You must be subscribed to the product. 33// 34// * The 35// instance type and operating system of the instance must support the product. For 36// example, you can't detach a volume from a Windows instance and attach it to a 37// Linux instance. 38// 39// For more information, see Attaching Amazon EBS volumes 40// (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-attaching-volume.html) 41// in the Amazon Elastic Compute Cloud User Guide. 42func (c *Client) AttachVolume(ctx context.Context, params *AttachVolumeInput, optFns ...func(*Options)) (*AttachVolumeOutput, error) { 43 if params == nil { 44 params = &AttachVolumeInput{} 45 } 46 47 result, metadata, err := c.invokeOperation(ctx, "AttachVolume", params, optFns, addOperationAttachVolumeMiddlewares) 48 if err != nil { 49 return nil, err 50 } 51 52 out := result.(*AttachVolumeOutput) 53 out.ResultMetadata = metadata 54 return out, nil 55} 56 57type AttachVolumeInput struct { 58 59 // The device name (for example, /dev/sdh or xvdh). 60 // 61 // This member is required. 62 Device *string 63 64 // The ID of the instance. 65 // 66 // This member is required. 67 InstanceId *string 68 69 // The ID of the EBS volume. The volume and instance must be within the same 70 // Availability Zone. 71 // 72 // This member is required. 73 VolumeId *string 74 75 // Checks whether you have the required permissions for the action, without 76 // actually making the request, and provides an error response. If you have the 77 // required permissions, the error response is DryRunOperation. Otherwise, it is 78 // UnauthorizedOperation. 79 DryRun bool 80} 81 82// Describes volume attachment details. 83type AttachVolumeOutput struct { 84 85 // The time stamp when the attachment initiated. 86 AttachTime *time.Time 87 88 // Indicates whether the EBS volume is deleted on instance termination. 89 DeleteOnTermination bool 90 91 // The device name. 92 Device *string 93 94 // The ID of the instance. 95 InstanceId *string 96 97 // The attachment state of the volume. 98 State types.VolumeAttachmentState 99 100 // The ID of the volume. 101 VolumeId *string 102 103 // Metadata pertaining to the operation's result. 104 ResultMetadata middleware.Metadata 105} 106 107func addOperationAttachVolumeMiddlewares(stack *middleware.Stack, options Options) (err error) { 108 err = stack.Serialize.Add(&awsEc2query_serializeOpAttachVolume{}, middleware.After) 109 if err != nil { 110 return err 111 } 112 err = stack.Deserialize.Add(&awsEc2query_deserializeOpAttachVolume{}, middleware.After) 113 if err != nil { 114 return err 115 } 116 if err = addSetLoggerMiddleware(stack, options); err != nil { 117 return err 118 } 119 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 120 return err 121 } 122 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 123 return err 124 } 125 if err = addResolveEndpointMiddleware(stack, options); err != nil { 126 return err 127 } 128 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 129 return err 130 } 131 if err = addRetryMiddlewares(stack, options); err != nil { 132 return err 133 } 134 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 135 return err 136 } 137 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 138 return err 139 } 140 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 141 return err 142 } 143 if err = addClientUserAgent(stack); err != nil { 144 return err 145 } 146 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 147 return err 148 } 149 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 150 return err 151 } 152 if err = addOpAttachVolumeValidationMiddleware(stack); err != nil { 153 return err 154 } 155 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opAttachVolume(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 170func newServiceMetadataMiddleware_opAttachVolume(region string) *awsmiddleware.RegisterServiceMetadata { 171 return &awsmiddleware.RegisterServiceMetadata{ 172 Region: region, 173 ServiceID: ServiceID, 174 SigningName: "ec2", 175 OperationName: "AttachVolume", 176 } 177} 178