1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ec2
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	"github.com/aws/aws-sdk-go-v2/service/ec2/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Exports an Amazon Machine Image (AMI) to a VM file. For more information, see
16// Exporting a VM Directory from an Amazon Machine Image (AMI)
17// (https://docs.aws.amazon.com/vm-import/latest/userguide/vmexport_image.html) in
18// the VM Import/Export User Guide.
19func (c *Client) ExportImage(ctx context.Context, params *ExportImageInput, optFns ...func(*Options)) (*ExportImageOutput, error) {
20	if params == nil {
21		params = &ExportImageInput{}
22	}
23
24	result, metadata, err := c.invokeOperation(ctx, "ExportImage", params, optFns, addOperationExportImageMiddlewares)
25	if err != nil {
26		return nil, err
27	}
28
29	out := result.(*ExportImageOutput)
30	out.ResultMetadata = metadata
31	return out, nil
32}
33
34type ExportImageInput struct {
35
36	// The disk image format.
37	//
38	// This member is required.
39	DiskImageFormat types.DiskImageFormat
40
41	// The ID of the image.
42	//
43	// This member is required.
44	ImageId *string
45
46	// Information about the destination Amazon S3 bucket. The bucket must exist and
47	// grant WRITE and READ_ACP permissions to the AWS account
48	// vm-import-export@amazon.com.
49	//
50	// This member is required.
51	S3ExportLocation *types.ExportTaskS3LocationRequest
52
53	// Token to enable idempotency for export image requests.
54	ClientToken *string
55
56	// A description of the image being exported. The maximum length is 255 characters.
57	Description *string
58
59	// Checks whether you have the required permissions for the action, without
60	// actually making the request, and provides an error response. If you have the
61	// required permissions, the error response is DryRunOperation. Otherwise, it is
62	// UnauthorizedOperation.
63	DryRun bool
64
65	// The name of the role that grants VM Import/Export permission to export images to
66	// your Amazon S3 bucket. If this parameter is not specified, the default role is
67	// named 'vmimport'.
68	RoleName *string
69
70	// The tags to apply to the image being exported.
71	TagSpecifications []types.TagSpecification
72}
73
74type ExportImageOutput struct {
75
76	// A description of the image being exported.
77	Description *string
78
79	// The disk image format for the exported image.
80	DiskImageFormat types.DiskImageFormat
81
82	// The ID of the export image task.
83	ExportImageTaskId *string
84
85	// The ID of the image.
86	ImageId *string
87
88	// The percent complete of the export image task.
89	Progress *string
90
91	// The name of the role that grants VM Import/Export permission to export images to
92	// your Amazon S3 bucket.
93	RoleName *string
94
95	// Information about the destination Amazon S3 bucket.
96	S3ExportLocation *types.ExportTaskS3Location
97
98	// The status of the export image task. The possible values are active, completed,
99	// deleting, and deleted.
100	Status *string
101
102	// The status message for the export image task.
103	StatusMessage *string
104
105	// Any tags assigned to the image being exported.
106	Tags []types.Tag
107
108	// Metadata pertaining to the operation's result.
109	ResultMetadata middleware.Metadata
110}
111
112func addOperationExportImageMiddlewares(stack *middleware.Stack, options Options) (err error) {
113	err = stack.Serialize.Add(&awsEc2query_serializeOpExportImage{}, middleware.After)
114	if err != nil {
115		return err
116	}
117	err = stack.Deserialize.Add(&awsEc2query_deserializeOpExportImage{}, middleware.After)
118	if err != nil {
119		return err
120	}
121	if err = addSetLoggerMiddleware(stack, options); err != nil {
122		return err
123	}
124	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
125		return err
126	}
127	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
128		return err
129	}
130	if err = addResolveEndpointMiddleware(stack, options); err != nil {
131		return err
132	}
133	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
134		return err
135	}
136	if err = addRetryMiddlewares(stack, options); err != nil {
137		return err
138	}
139	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
140		return err
141	}
142	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
143		return err
144	}
145	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
146		return err
147	}
148	if err = addClientUserAgent(stack); err != nil {
149		return err
150	}
151	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
152		return err
153	}
154	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
155		return err
156	}
157	if err = addIdempotencyToken_opExportImageMiddleware(stack, options); err != nil {
158		return err
159	}
160	if err = addOpExportImageValidationMiddleware(stack); err != nil {
161		return err
162	}
163	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opExportImage(options.Region), middleware.Before); err != nil {
164		return err
165	}
166	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
167		return err
168	}
169	if err = addResponseErrorMiddleware(stack); err != nil {
170		return err
171	}
172	if err = addRequestResponseLogging(stack, options); err != nil {
173		return err
174	}
175	return nil
176}
177
178type idempotencyToken_initializeOpExportImage struct {
179	tokenProvider IdempotencyTokenProvider
180}
181
182func (*idempotencyToken_initializeOpExportImage) ID() string {
183	return "OperationIdempotencyTokenAutoFill"
184}
185
186func (m *idempotencyToken_initializeOpExportImage) HandleInitialize(ctx context.Context, in middleware.InitializeInput, next middleware.InitializeHandler) (
187	out middleware.InitializeOutput, metadata middleware.Metadata, err error,
188) {
189	if m.tokenProvider == nil {
190		return next.HandleInitialize(ctx, in)
191	}
192
193	input, ok := in.Parameters.(*ExportImageInput)
194	if !ok {
195		return out, metadata, fmt.Errorf("expected middleware input to be of type *ExportImageInput ")
196	}
197
198	if input.ClientToken == nil {
199		t, err := m.tokenProvider.GetIdempotencyToken()
200		if err != nil {
201			return out, metadata, err
202		}
203		input.ClientToken = &t
204	}
205	return next.HandleInitialize(ctx, in)
206}
207func addIdempotencyToken_opExportImageMiddleware(stack *middleware.Stack, cfg Options) error {
208	return stack.Initialize.Add(&idempotencyToken_initializeOpExportImage{tokenProvider: cfg.IdempotencyTokenProvider}, middleware.Before)
209}
210
211func newServiceMetadataMiddleware_opExportImage(region string) *awsmiddleware.RegisterServiceMetadata {
212	return &awsmiddleware.RegisterServiceMetadata{
213		Region:        region,
214		ServiceID:     ServiceID,
215		SigningName:   "ec2",
216		OperationName: "ExportImage",
217	}
218}
219