1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package elasticache
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/elasticache/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// Makes a copy of an existing snapshot. This operation is valid for Redis only.
15// Users or groups that have permissions to use the CopySnapshot operation
16//
17// can
18// create their own Amazon S3 buckets and copy snapshots to it. To control access
19// to your snapshots, use an IAM policy to control who has the ability to use the
20// CopySnapshot operation. For more information about using IAM to control the use
21// of ElastiCache operations, see Exporting Snapshots
22// (https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/backups-exporting.html)
23// and Authentication & Access Control
24// (https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/IAM.html). You
25// could receive the following error messages. Error Messages
26//
27// * Error Message: The
28// S3 bucket %s is outside of the region. Solution: Create an Amazon S3 bucket in
29// the same region as your snapshot. For more information, see Step 1: Create an
30// Amazon S3 Bucket
31// (https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/backups-exporting.html#backups-exporting-create-s3-bucket)
32// in the ElastiCache User Guide.
33//
34// * Error Message: The S3 bucket %s does not
35// exist. Solution: Create an Amazon S3 bucket in the same region as your snapshot.
36// For more information, see Step 1: Create an Amazon S3 Bucket
37// (https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/backups-exporting.html#backups-exporting-create-s3-bucket)
38// in the ElastiCache User Guide.
39//
40// * Error Message: The S3 bucket %s is not owned
41// by the authenticated user. Solution: Create an Amazon S3 bucket in the same
42// region as your snapshot. For more information, see Step 1: Create an Amazon S3
43// Bucket
44// (https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/backups-exporting.html#backups-exporting-create-s3-bucket)
45// in the ElastiCache User Guide.
46//
47// * Error Message: The authenticated user does not
48// have sufficient permissions to perform the desired activity. Solution: Contact
49// your system administrator to get the needed permissions.
50//
51// * Error Message: The
52// S3 bucket %s already contains an object with key %s. Solution: Give the
53// TargetSnapshotName a new and unique value. If exporting a snapshot, you could
54// alternatively create a new Amazon S3 bucket and use this same value for
55// TargetSnapshotName.
56//
57// * Error Message: ElastiCache has not been granted READ
58// permissions %s on the S3 Bucket. Solution: Add List and Read permissions on the
59// bucket. For more information, see Step 2: Grant ElastiCache Access to Your
60// Amazon S3 Bucket
61// (https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/backups-exporting.html#backups-exporting-grant-access)
62// in the ElastiCache User Guide.
63//
64// * Error Message: ElastiCache has not been
65// granted WRITE permissions %s on the S3 Bucket. Solution: Add Upload/Delete
66// permissions on the bucket. For more information, see Step 2: Grant ElastiCache
67// Access to Your Amazon S3 Bucket
68// (https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/backups-exporting.html#backups-exporting-grant-access)
69// in the ElastiCache User Guide.
70//
71// * Error Message: ElastiCache has not been
72// granted READ_ACP permissions %s on the S3 Bucket. Solution: Add View Permissions
73// on the bucket. For more information, see Step 2: Grant ElastiCache Access to
74// Your Amazon S3 Bucket
75// (https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/backups-exporting.html#backups-exporting-grant-access)
76// in the ElastiCache User Guide.
77func (c *Client) CopySnapshot(ctx context.Context, params *CopySnapshotInput, optFns ...func(*Options)) (*CopySnapshotOutput, error) {
78	if params == nil {
79		params = &CopySnapshotInput{}
80	}
81
82	result, metadata, err := c.invokeOperation(ctx, "CopySnapshot", params, optFns, addOperationCopySnapshotMiddlewares)
83	if err != nil {
84		return nil, err
85	}
86
87	out := result.(*CopySnapshotOutput)
88	out.ResultMetadata = metadata
89	return out, nil
90}
91
92// Represents the input of a CopySnapshotMessage operation.
93type CopySnapshotInput struct {
94
95	// The name of an existing snapshot from which to make a copy.
96	//
97	// This member is required.
98	SourceSnapshotName *string
99
100	// A name for the snapshot copy. ElastiCache does not permit overwriting a
101	// snapshot, therefore this name must be unique within its context - ElastiCache or
102	// an Amazon S3 bucket if exporting.
103	//
104	// This member is required.
105	TargetSnapshotName *string
106
107	// The ID of the KMS key used to encrypt the target snapshot.
108	KmsKeyId *string
109
110	// The Amazon S3 bucket to which the snapshot is exported. This parameter is used
111	// only when exporting a snapshot for external access. When using this parameter to
112	// export a snapshot, be sure Amazon ElastiCache has the needed permissions to this
113	// S3 bucket. For more information, see Step 2: Grant ElastiCache Access to Your
114	// Amazon S3 Bucket
115	// (http://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/backups-exporting.html#backups-exporting-grant-access)
116	// in the Amazon ElastiCache User Guide. For more information, see Exporting a
117	// Snapshot
118	// (https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Snapshots.Exporting.html)
119	// in the Amazon ElastiCache User Guide.
120	TargetBucket *string
121}
122
123type CopySnapshotOutput struct {
124
125	// Represents a copy of an entire Redis cluster as of the time when the snapshot
126	// was taken.
127	Snapshot *types.Snapshot
128
129	// Metadata pertaining to the operation's result.
130	ResultMetadata middleware.Metadata
131}
132
133func addOperationCopySnapshotMiddlewares(stack *middleware.Stack, options Options) (err error) {
134	err = stack.Serialize.Add(&awsAwsquery_serializeOpCopySnapshot{}, middleware.After)
135	if err != nil {
136		return err
137	}
138	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpCopySnapshot{}, middleware.After)
139	if err != nil {
140		return err
141	}
142	if err = addSetLoggerMiddleware(stack, options); err != nil {
143		return err
144	}
145	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
146		return err
147	}
148	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
149		return err
150	}
151	if err = addResolveEndpointMiddleware(stack, options); err != nil {
152		return err
153	}
154	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
155		return err
156	}
157	if err = addRetryMiddlewares(stack, options); err != nil {
158		return err
159	}
160	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
161		return err
162	}
163	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
164		return err
165	}
166	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
167		return err
168	}
169	if err = addClientUserAgent(stack); err != nil {
170		return err
171	}
172	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
173		return err
174	}
175	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
176		return err
177	}
178	if err = addOpCopySnapshotValidationMiddleware(stack); err != nil {
179		return err
180	}
181	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCopySnapshot(options.Region), middleware.Before); err != nil {
182		return err
183	}
184	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
185		return err
186	}
187	if err = addResponseErrorMiddleware(stack); err != nil {
188		return err
189	}
190	if err = addRequestResponseLogging(stack, options); err != nil {
191		return err
192	}
193	return nil
194}
195
196func newServiceMetadataMiddleware_opCopySnapshot(region string) *awsmiddleware.RegisterServiceMetadata {
197	return &awsmiddleware.RegisterServiceMetadata{
198		Region:        region,
199		ServiceID:     ServiceID,
200		SigningName:   "elasticache",
201		OperationName: "CopySnapshot",
202	}
203}
204