1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package lightsail
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/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. You can take a snapshot of an attached disk that is in use; however,
17// snapshots only capture data that has been written to your disk at the time the
18// snapshot command is issued. This may exclude any data that has been cached by
19// any applications or the operating system. If you can pause any file systems on
20// the disk long enough to take a snapshot, your snapshot should be complete.
21// Nevertheless, if you cannot pause all file writes to the disk, you should
22// unmount the disk from within the Lightsail instance, issue the create disk
23// snapshot command, and then remount the disk to ensure a consistent and complete
24// snapshot. You may remount and use your disk while the snapshot status is
25// pending. You can also use this operation to create a snapshot of an instance's
26// system volume. You might want to do this, for example, to recover data from the
27// system volume of a botched instance or to create a backup of the system volume
28// like you would for a block storage disk. To create a snapshot of a system
29// volume, just define the instance name parameter when issuing the snapshot
30// command, and a snapshot of the defined instance's system volume will be created.
31// After the snapshot is available, you can create a block storage disk from the
32// snapshot and attach it to a running instance to access the data on the disk. The
33// create disk snapshot operation supports tag-based access control via request
34// tags. For more information, see the Lightsail Dev Guide
35// (https://lightsail.aws.amazon.com/ls/docs/en/articles/amazon-lightsail-controlling-access-using-tags).
36func (c *Client) CreateDiskSnapshot(ctx context.Context, params *CreateDiskSnapshotInput, optFns ...func(*Options)) (*CreateDiskSnapshotOutput, error) {
37	if params == nil {
38		params = &CreateDiskSnapshotInput{}
39	}
40
41	result, metadata, err := c.invokeOperation(ctx, "CreateDiskSnapshot", params, optFns, addOperationCreateDiskSnapshotMiddlewares)
42	if err != nil {
43		return nil, err
44	}
45
46	out := result.(*CreateDiskSnapshotOutput)
47	out.ResultMetadata = metadata
48	return out, nil
49}
50
51type CreateDiskSnapshotInput struct {
52
53	// The name of the destination disk snapshot (e.g., my-disk-snapshot) based on the
54	// source disk.
55	//
56	// This member is required.
57	DiskSnapshotName *string
58
59	// The unique name of the source disk (e.g., Disk-Virginia-1). This parameter
60	// cannot be defined together with the instance name parameter. The disk name and
61	// instance name parameters are mutually exclusive.
62	DiskName *string
63
64	// The unique name of the source instance (e.g., Amazon_Linux-512MB-Virginia-1).
65	// When this is defined, a snapshot of the instance's system volume is created.
66	// This parameter cannot be defined together with the disk name parameter. The
67	// instance name and disk name parameters are mutually exclusive.
68	InstanceName *string
69
70	// The tag keys and optional values to add to the resource during create. Use the
71	// TagResource action to tag a resource after it's created.
72	Tags []types.Tag
73}
74
75type CreateDiskSnapshotOutput struct {
76
77	// An array of objects that describe the result of the action, such as the status
78	// of the request, the timestamp of the request, and the resources affected by the
79	// request.
80	Operations []types.Operation
81
82	// Metadata pertaining to the operation's result.
83	ResultMetadata middleware.Metadata
84}
85
86func addOperationCreateDiskSnapshotMiddlewares(stack *middleware.Stack, options Options) (err error) {
87	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateDiskSnapshot{}, middleware.After)
88	if err != nil {
89		return err
90	}
91	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateDiskSnapshot{}, middleware.After)
92	if err != nil {
93		return err
94	}
95	if err = addSetLoggerMiddleware(stack, options); err != nil {
96		return err
97	}
98	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
99		return err
100	}
101	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
102		return err
103	}
104	if err = addResolveEndpointMiddleware(stack, options); err != nil {
105		return err
106	}
107	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
108		return err
109	}
110	if err = addRetryMiddlewares(stack, options); err != nil {
111		return err
112	}
113	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
114		return err
115	}
116	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
117		return err
118	}
119	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
120		return err
121	}
122	if err = addClientUserAgent(stack); err != nil {
123		return err
124	}
125	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
126		return err
127	}
128	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
129		return err
130	}
131	if err = addOpCreateDiskSnapshotValidationMiddleware(stack); err != nil {
132		return err
133	}
134	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateDiskSnapshot(options.Region), middleware.Before); err != nil {
135		return err
136	}
137	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
138		return err
139	}
140	if err = addResponseErrorMiddleware(stack); err != nil {
141		return err
142	}
143	if err = addRequestResponseLogging(stack, options); err != nil {
144		return err
145	}
146	return nil
147}
148
149func newServiceMetadataMiddleware_opCreateDiskSnapshot(region string) *awsmiddleware.RegisterServiceMetadata {
150	return &awsmiddleware.RegisterServiceMetadata{
151		Region:        region,
152		ServiceID:     ServiceID,
153		SigningName:   "lightsail",
154		OperationName: "CreateDiskSnapshot",
155	}
156}
157