1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package rds 4 5import ( 6 "context" 7 "fmt" 8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 9 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 10 presignedurlcust "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url" 11 "github.com/aws/aws-sdk-go-v2/service/rds/types" 12 "github.com/aws/smithy-go/middleware" 13 smithyhttp "github.com/aws/smithy-go/transport/http" 14) 15 16// Copies the specified DB snapshot. The source DB snapshot must be in the 17// available state. You can copy a snapshot from one Amazon Web Services Region to 18// another. In that case, the Amazon Web Services Region where you call the 19// CopyDBSnapshot action is the destination Amazon Web Services Region for the DB 20// snapshot copy. For more information about copying snapshots, see Copying a DB 21// Snapshot 22// (https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CopySnapshot.html#USER_CopyDBSnapshot) 23// in the Amazon RDS User Guide. 24func (c *Client) CopyDBSnapshot(ctx context.Context, params *CopyDBSnapshotInput, optFns ...func(*Options)) (*CopyDBSnapshotOutput, error) { 25 if params == nil { 26 params = &CopyDBSnapshotInput{} 27 } 28 29 result, metadata, err := c.invokeOperation(ctx, "CopyDBSnapshot", params, optFns, c.addOperationCopyDBSnapshotMiddlewares) 30 if err != nil { 31 return nil, err 32 } 33 34 out := result.(*CopyDBSnapshotOutput) 35 out.ResultMetadata = metadata 36 return out, nil 37} 38 39// 40type CopyDBSnapshotInput struct { 41 42 // The identifier for the source DB snapshot. If the source snapshot is in the same 43 // Amazon Web Services Region as the copy, specify a valid DB snapshot identifier. 44 // For example, you might specify rds:mysql-instance1-snapshot-20130805. If the 45 // source snapshot is in a different Amazon Web Services Region than the copy, 46 // specify a valid DB snapshot ARN. For example, you might specify 47 // arn:aws:rds:us-west-2:123456789012:snapshot:mysql-instance1-snapshot-20130805. 48 // If you are copying from a shared manual DB snapshot, this parameter must be the 49 // Amazon Resource Name (ARN) of the shared DB snapshot. If you are copying an 50 // encrypted snapshot this parameter must be in the ARN format for the source 51 // Amazon Web Services Region, and must match the SourceDBSnapshotIdentifier in the 52 // PreSignedUrl parameter. Constraints: 53 // 54 // * Must specify a valid system snapshot in 55 // the "available" state. 56 // 57 // Example: rds:mydb-2012-04-02-00-01 Example: 58 // arn:aws:rds:us-west-2:123456789012:snapshot:mysql-instance1-snapshot-20130805 59 // 60 // This member is required. 61 SourceDBSnapshotIdentifier *string 62 63 // The identifier for the copy of the snapshot. Constraints: 64 // 65 // * Can't be null, 66 // empty, or blank 67 // 68 // * Must contain from 1 to 255 letters, numbers, or hyphens 69 // 70 // * 71 // First character must be a letter 72 // 73 // * Can't end with a hyphen or contain two 74 // consecutive hyphens 75 // 76 // Example: my-db-snapshot 77 // 78 // This member is required. 79 TargetDBSnapshotIdentifier *string 80 81 // A value that indicates whether to copy all tags from the source DB snapshot to 82 // the target DB snapshot. By default, tags are not copied. 83 CopyTags *bool 84 85 // The Amazon Web Services KMS key identifier for an encrypted DB snapshot. The 86 // Amazon Web Services KMS key identifier is the key ARN, key ID, alias ARN, or 87 // alias name for the Amazon Web Services KMS customer master key (CMK). If you 88 // copy an encrypted DB snapshot from your Amazon Web Services account, you can 89 // specify a value for this parameter to encrypt the copy with a new Amazon Web 90 // Services KMS CMK. If you don't specify a value for this parameter, then the copy 91 // of the DB snapshot is encrypted with the same Amazon Web Services KMS key as the 92 // source DB snapshot. If you copy an encrypted DB snapshot that is shared from 93 // another Amazon Web Services account, then you must specify a value for this 94 // parameter. If you specify this parameter when you copy an unencrypted snapshot, 95 // the copy is encrypted. If you copy an encrypted snapshot to a different Amazon 96 // Web Services Region, then you must specify a Amazon Web Services KMS key 97 // identifier for the destination Amazon Web Services Region. Amazon Web Services 98 // KMS CMKs are specific to the Amazon Web Services Region that they are created 99 // in, and you can't use CMKs from one Amazon Web Services Region in another Amazon 100 // Web Services Region. 101 KmsKeyId *string 102 103 // The name of an option group to associate with the copy of the snapshot. Specify 104 // this option if you are copying a snapshot from one Amazon Web Services Region to 105 // another, and your DB instance uses a nondefault option group. If your source DB 106 // instance uses Transparent Data Encryption for Oracle or Microsoft SQL Server, 107 // you must specify this option when copying across Amazon Web Services Regions. 108 // For more information, see Option group considerations 109 // (https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_CopySnapshot.html#USER_CopySnapshot.Options) 110 // in the Amazon RDS User Guide. 111 OptionGroupName *string 112 113 // The URL that contains a Signature Version 4 signed request for the 114 // CopyDBSnapshot API action in the source Amazon Web Services Region that contains 115 // the source DB snapshot to copy. You must specify this parameter when you copy an 116 // encrypted DB snapshot from another Amazon Web Services Region by using the 117 // Amazon RDS API. Don't specify PreSignedUrl when you are copying an encrypted DB 118 // snapshot in the same Amazon Web Services Region. The presigned URL must be a 119 // valid request for the CopyDBSnapshot API action that can be executed in the 120 // source Amazon Web Services Region that contains the encrypted DB snapshot to be 121 // copied. The presigned URL request must contain the following parameter 122 // values: 123 // 124 // * DestinationRegion - The Amazon Web Services Region that the encrypted 125 // DB snapshot is copied to. This Amazon Web Services Region is the same one where 126 // the CopyDBSnapshot action is called that contains this presigned URL. For 127 // example, if you copy an encrypted DB snapshot from the us-west-2 Amazon Web 128 // Services Region to the us-east-1 Amazon Web Services Region, then you call the 129 // CopyDBSnapshot action in the us-east-1 Amazon Web Services Region and provide a 130 // presigned URL that contains a call to the CopyDBSnapshot action in the us-west-2 131 // Amazon Web Services Region. For this example, the DestinationRegion in the 132 // presigned URL must be set to the us-east-1 Amazon Web Services Region. 133 // 134 // * 135 // KmsKeyId - The Amazon Web Services KMS key identifier for the customer master 136 // key (CMK) to use to encrypt the copy of the DB snapshot in the destination 137 // Amazon Web Services Region. This is the same identifier for both the 138 // CopyDBSnapshot action that is called in the destination Amazon Web Services 139 // Region, and the action contained in the presigned URL. 140 // 141 // * 142 // SourceDBSnapshotIdentifier - The DB snapshot identifier for the encrypted 143 // snapshot to be copied. This identifier must be in the Amazon Resource Name (ARN) 144 // format for the source Amazon Web Services Region. For example, if you are 145 // copying an encrypted DB snapshot from the us-west-2 Amazon Web Services Region, 146 // then your SourceDBSnapshotIdentifier looks like the following example: 147 // arn:aws:rds:us-west-2:123456789012:snapshot:mysql-instance1-snapshot-20161115. 148 // 149 // To 150 // learn how to generate a Signature Version 4 signed request, see Authenticating 151 // Requests: Using Query Parameters (Amazon Web Services Signature Version 4) 152 // (https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-query-string-auth.html) 153 // and Signature Version 4 Signing Process 154 // (https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html). If you 155 // are using an Amazon Web Services SDK tool or the CLI, you can specify 156 // SourceRegion (or --source-region for the CLI) instead of specifying PreSignedUrl 157 // manually. Specifying SourceRegion autogenerates a pre-signed URL that is a valid 158 // request for the operation that can be executed in the source Amazon Web Services 159 // Region. 160 PreSignedUrl *string 161 162 // The AWS region the resource is in. The presigned URL will be created with this 163 // region, if the PresignURL member is empty set. 164 SourceRegion *string 165 166 // A list of tags. For more information, see Tagging Amazon RDS Resources 167 // (https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Tagging.html) in 168 // the Amazon RDS User Guide. 169 Tags []types.Tag 170 171 // The external custom Availability Zone (CAZ) identifier for the target CAZ. 172 // Example: rds-caz-aiqhTgQv. 173 TargetCustomAvailabilityZone *string 174 175 // Used by the SDK's PresignURL autofill customization to specify the region the of 176 // the client's request. 177 destinationRegion *string 178 179 noSmithyDocumentSerde 180} 181 182type CopyDBSnapshotOutput struct { 183 184 // Contains the details of an Amazon RDS DB snapshot. This data type is used as a 185 // response element in the DescribeDBSnapshots action. 186 DBSnapshot *types.DBSnapshot 187 188 // Metadata pertaining to the operation's result. 189 ResultMetadata middleware.Metadata 190 191 noSmithyDocumentSerde 192} 193 194func (c *Client) addOperationCopyDBSnapshotMiddlewares(stack *middleware.Stack, options Options) (err error) { 195 err = stack.Serialize.Add(&awsAwsquery_serializeOpCopyDBSnapshot{}, middleware.After) 196 if err != nil { 197 return err 198 } 199 err = stack.Deserialize.Add(&awsAwsquery_deserializeOpCopyDBSnapshot{}, middleware.After) 200 if err != nil { 201 return err 202 } 203 if err = addSetLoggerMiddleware(stack, options); err != nil { 204 return err 205 } 206 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 207 return err 208 } 209 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 210 return err 211 } 212 if err = addResolveEndpointMiddleware(stack, options); err != nil { 213 return err 214 } 215 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 216 return err 217 } 218 if err = addRetryMiddlewares(stack, options); err != nil { 219 return err 220 } 221 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 222 return err 223 } 224 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 225 return err 226 } 227 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 228 return err 229 } 230 if err = addClientUserAgent(stack); err != nil { 231 return err 232 } 233 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 234 return err 235 } 236 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 237 return err 238 } 239 if err = addCopyDBSnapshotPresignURLMiddleware(stack, options); err != nil { 240 return err 241 } 242 if err = addOpCopyDBSnapshotValidationMiddleware(stack); err != nil { 243 return err 244 } 245 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCopyDBSnapshot(options.Region), middleware.Before); err != nil { 246 return err 247 } 248 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 249 return err 250 } 251 if err = addResponseErrorMiddleware(stack); err != nil { 252 return err 253 } 254 if err = addRequestResponseLogging(stack, options); err != nil { 255 return err 256 } 257 return nil 258} 259 260func copyCopyDBSnapshotInputForPresign(params interface{}) (interface{}, error) { 261 input, ok := params.(*CopyDBSnapshotInput) 262 if !ok { 263 return nil, fmt.Errorf("expect *CopyDBSnapshotInput type, got %T", params) 264 } 265 cpy := *input 266 return &cpy, nil 267} 268func getCopyDBSnapshotPreSignedUrl(params interface{}) (string, bool, error) { 269 input, ok := params.(*CopyDBSnapshotInput) 270 if !ok { 271 return ``, false, fmt.Errorf("expect *CopyDBSnapshotInput type, got %T", params) 272 } 273 if input.PreSignedUrl == nil || len(*input.PreSignedUrl) == 0 { 274 return ``, false, nil 275 } 276 return *input.PreSignedUrl, true, nil 277} 278func getCopyDBSnapshotSourceRegion(params interface{}) (string, bool, error) { 279 input, ok := params.(*CopyDBSnapshotInput) 280 if !ok { 281 return ``, false, fmt.Errorf("expect *CopyDBSnapshotInput type, got %T", params) 282 } 283 if input.SourceRegion == nil || len(*input.SourceRegion) == 0 { 284 return ``, false, nil 285 } 286 return *input.SourceRegion, true, nil 287} 288func setCopyDBSnapshotPreSignedUrl(params interface{}, value string) error { 289 input, ok := params.(*CopyDBSnapshotInput) 290 if !ok { 291 return fmt.Errorf("expect *CopyDBSnapshotInput type, got %T", params) 292 } 293 input.PreSignedUrl = &value 294 return nil 295} 296func setCopyDBSnapshotdestinationRegion(params interface{}, value string) error { 297 input, ok := params.(*CopyDBSnapshotInput) 298 if !ok { 299 return fmt.Errorf("expect *CopyDBSnapshotInput type, got %T", params) 300 } 301 input.destinationRegion = &value 302 return nil 303} 304func addCopyDBSnapshotPresignURLMiddleware(stack *middleware.Stack, options Options) error { 305 return presignedurlcust.AddMiddleware(stack, presignedurlcust.Options{ 306 Accessor: presignedurlcust.ParameterAccessor{ 307 GetPresignedURL: getCopyDBSnapshotPreSignedUrl, 308 309 GetSourceRegion: getCopyDBSnapshotSourceRegion, 310 311 CopyInput: copyCopyDBSnapshotInputForPresign, 312 313 SetDestinationRegion: setCopyDBSnapshotdestinationRegion, 314 315 SetPresignedURL: setCopyDBSnapshotPreSignedUrl, 316 }, 317 Presigner: &presignAutoFillCopyDBSnapshotClient{client: NewPresignClient(New(options))}, 318 }) 319} 320 321type presignAutoFillCopyDBSnapshotClient struct { 322 client *PresignClient 323} 324 325// PresignURL is a middleware accessor that satisfies URLPresigner interface. 326func (c *presignAutoFillCopyDBSnapshotClient) PresignURL(ctx context.Context, srcRegion string, params interface{}) (*v4.PresignedHTTPRequest, error) { 327 input, ok := params.(*CopyDBSnapshotInput) 328 if !ok { 329 return nil, fmt.Errorf("expect *CopyDBSnapshotInput type, got %T", params) 330 } 331 optFn := func(o *Options) { 332 o.Region = srcRegion 333 o.APIOptions = append(o.APIOptions, presignedurlcust.RemoveMiddleware) 334 } 335 presignOptFn := WithPresignClientFromClientOptions(optFn) 336 return c.client.PresignCopyDBSnapshot(ctx, input, presignOptFn) 337} 338 339func newServiceMetadataMiddleware_opCopyDBSnapshot(region string) *awsmiddleware.RegisterServiceMetadata { 340 return &awsmiddleware.RegisterServiceMetadata{ 341 Region: region, 342 ServiceID: ServiceID, 343 SigningName: "rds", 344 OperationName: "CopyDBSnapshot", 345 } 346} 347 348// PresignCopyDBSnapshot is used to generate a presigned HTTP Request which 349// contains presigned URL, signed headers and HTTP method used. 350func (c *PresignClient) PresignCopyDBSnapshot(ctx context.Context, params *CopyDBSnapshotInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error) { 351 if params == nil { 352 params = &CopyDBSnapshotInput{} 353 } 354 options := c.options.copy() 355 for _, fn := range optFns { 356 fn(&options) 357 } 358 clientOptFns := append(options.ClientOptions, withNopHTTPClientAPIOption) 359 360 result, _, err := c.client.invokeOperation(ctx, "CopyDBSnapshot", params, clientOptFns, 361 c.client.addOperationCopyDBSnapshotMiddlewares, 362 presignConverter(options).convertToPresignMiddleware, 363 ) 364 if err != nil { 365 return nil, err 366 } 367 368 out := result.(*v4.PresignedHTTPRequest) 369 return out, nil 370} 371