1 // Code generated by smithy-go-codegen DO NOT EDIT.
2 3 package lightsail
4 5 import (
6 "context"
7 "fmt"
8 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9 "github.com/aws/aws-sdk-go-v2/service/lightsail/types"
10 "github.com/aws/smithy-go/middleware"
11 smithyhttp "github.com/aws/smithy-go/transport/http"
12 )
13 14 // Creates a snapshot of a block storage disk. You can use snapshots for backups,
15 // to make copies of disks, and to save data before shutting down a Lightsail
16 // instance.
17 //
18 // You can take a snapshot of an attached disk that is in use; however, snapshots
19 // only capture data that has been written to your disk at the time the snapshot
20 // command is issued. This may exclude any data that has been cached by any
21 // applications or the operating system. If you can pause any file systems on the
22 // disk long enough to take a snapshot, your snapshot should be complete.
23 // Nevertheless, if you cannot pause all file writes to the disk, you should
24 // unmount the disk from within the Lightsail instance, issue the create disk
25 // snapshot command, and then remount the disk to ensure a consistent and complete
26 // snapshot. You may remount and use your disk while the snapshot status is
27 // pending.
28 //
29 // You can also use this operation to create a snapshot of an instance's system
30 // volume. You might want to do this, for example, to recover data from the system
31 // volume of a botched instance or to create a backup of the system volume like you
32 // would for a block storage disk. To create a snapshot of a system volume, just
33 // define the instance name parameter when issuing the snapshot command, and a
34 // snapshot of the defined instance's system volume will be created. After the
35 // snapshot is available, you can create a block storage disk from the snapshot and
36 // attach it to a running instance to access the data on the disk.
37 //
38 // The create disk snapshot operation supports tag-based access control via
39 // request tags. For more information, see the [Amazon Lightsail Developer Guide].
40 //
41 // [Amazon Lightsail Developer Guide]: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-controlling-access-using-tags
42 func (c *Client) CreateDiskSnapshot(ctx context.Context, params *CreateDiskSnapshotInput, optFns ...func(*Options)) (*CreateDiskSnapshotOutput, error) {
43 if params == nil {
44 params = &CreateDiskSnapshotInput{}
45 }
46 47 result, metadata, err := c.invokeOperation(ctx, "CreateDiskSnapshot", params, optFns, c.addOperationCreateDiskSnapshotMiddlewares)
48 if err != nil {
49 return nil, err
50 }
51 52 out := result.(*CreateDiskSnapshotOutput)
53 out.ResultMetadata = metadata
54 return out, nil
55 }
56 57 type CreateDiskSnapshotInput struct {
58 59 // The name of the destination disk snapshot ( my-disk-snapshot ) based on the
60 // source disk.
61 //
62 // This member is required.
63 DiskSnapshotName *string
64 65 // The unique name of the source disk ( Disk-Virginia-1 ).
66 //
67 // This parameter cannot be defined together with the instance name parameter. The
68 // disk name and instance name parameters are mutually exclusive.
69 DiskName *string
70 71 // The unique name of the source instance ( Amazon_Linux-512MB-Virginia-1 ). When
72 // this is defined, a snapshot of the instance's system volume is created.
73 //
74 // This parameter cannot be defined together with the disk name parameter. The
75 // instance name and disk name parameters are mutually exclusive.
76 InstanceName *string
77 78 // The tag keys and optional values to add to the resource during create.
79 //
80 // Use the TagResource action to tag a resource after it's created.
81 Tags []types.Tag
82 83 noSmithyDocumentSerde
84 }
85 86 type CreateDiskSnapshotOutput struct {
87 88 // An array of objects that describe the result of the action, such as the status
89 // of the request, the timestamp of the request, and the resources affected by the
90 // request.
91 Operations []types.Operation
92 93 // Metadata pertaining to the operation's result.
94 ResultMetadata middleware.Metadata
95 96 noSmithyDocumentSerde
97 }
98 99 func (c *Client) addOperationCreateDiskSnapshotMiddlewares(stack *middleware.Stack, options Options) (err error) {
100 if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
101 return err
102 }
103 err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateDiskSnapshot{}, middleware.After)
104 if err != nil {
105 return err
106 }
107 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateDiskSnapshot{}, middleware.After)
108 if err != nil {
109 return err
110 }
111 if err := addProtocolFinalizerMiddlewares(stack, options, "CreateDiskSnapshot"); err != nil {
112 return fmt.Errorf("add protocol finalizers: %v", err)
113 }
114 115 if err = addlegacyEndpointContextSetter(stack, options); err != nil {
116 return err
117 }
118 if err = addSetLoggerMiddleware(stack, options); err != nil {
119 return err
120 }
121 if err = addClientRequestID(stack); err != nil {
122 return err
123 }
124 if err = addComputeContentLength(stack); err != nil {
125 return err
126 }
127 if err = addResolveEndpointMiddleware(stack, options); err != nil {
128 return err
129 }
130 if err = addComputePayloadSHA256(stack); err != nil {
131 return err
132 }
133 if err = addRetry(stack, options); err != nil {
134 return err
135 }
136 if err = addRawResponseToMetadata(stack); err != nil {
137 return err
138 }
139 if err = addRecordResponseTiming(stack); err != nil {
140 return err
141 }
142 if err = addSpanRetryLoop(stack, options); err != nil {
143 return err
144 }
145 if err = addClientUserAgent(stack, options); err != nil {
146 return err
147 }
148 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
149 return err
150 }
151 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
152 return err
153 }
154 if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
155 return err
156 }
157 if err = addTimeOffsetBuild(stack, c); err != nil {
158 return err
159 }
160 if err = addUserAgentRetryMode(stack, options); err != nil {
161 return err
162 }
163 if err = addCredentialSource(stack, options); err != nil {
164 return err
165 }
166 if err = addOpCreateDiskSnapshotValidationMiddleware(stack); err != nil {
167 return err
168 }
169 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateDiskSnapshot(options.Region), middleware.Before); err != nil {
170 return err
171 }
172 if err = addRecursionDetection(stack); err != nil {
173 return err
174 }
175 if err = addRequestIDRetrieverMiddleware(stack); err != nil {
176 return err
177 }
178 if err = addResponseErrorMiddleware(stack); err != nil {
179 return err
180 }
181 if err = addRequestResponseLogging(stack, options); err != nil {
182 return err
183 }
184 if err = addDisableHTTPSMiddleware(stack, options); err != nil {
185 return err
186 }
187 if err = addInterceptBeforeRetryLoop(stack, options); err != nil {
188 return err
189 }
190 if err = addInterceptAttempt(stack, options); err != nil {
191 return err
192 }
193 if err = addInterceptors(stack, options); err != nil {
194 return err
195 }
196 return nil
197 }
198 199 func newServiceMetadataMiddleware_opCreateDiskSnapshot(region string) *awsmiddleware.RegisterServiceMetadata {
200 return &awsmiddleware.RegisterServiceMetadata{
201 Region: region,
202 ServiceID: ServiceID,
203 OperationName: "CreateDiskSnapshot",
204 }
205 }
206