api_op_CreateDistribution.go raw
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 an Amazon Lightsail content delivery network (CDN) distribution.
15 //
16 // A distribution is a globally distributed network of caching servers that
17 // improve the performance of your website or web application hosted on a Lightsail
18 // instance. For more information, see [Content delivery networks in Amazon Lightsail].
19 //
20 // [Content delivery networks in Amazon Lightsail]: https://docs.aws.amazon.com/lightsail/latest/userguide/amazon-lightsail-content-delivery-network-distributions
21 func (c *Client) CreateDistribution(ctx context.Context, params *CreateDistributionInput, optFns ...func(*Options)) (*CreateDistributionOutput, error) {
22 if params == nil {
23 params = &CreateDistributionInput{}
24 }
25
26 result, metadata, err := c.invokeOperation(ctx, "CreateDistribution", params, optFns, c.addOperationCreateDistributionMiddlewares)
27 if err != nil {
28 return nil, err
29 }
30
31 out := result.(*CreateDistributionOutput)
32 out.ResultMetadata = metadata
33 return out, nil
34 }
35
36 type CreateDistributionInput struct {
37
38 // The bundle ID to use for the distribution.
39 //
40 // A distribution bundle describes the specifications of your distribution, such
41 // as the monthly cost and monthly network transfer quota.
42 //
43 // Use the GetDistributionBundles action to get a list of distribution bundle IDs
44 // that you can specify.
45 //
46 // This member is required.
47 BundleId *string
48
49 // An object that describes the default cache behavior for the distribution.
50 //
51 // This member is required.
52 DefaultCacheBehavior *types.CacheBehavior
53
54 // The name for the distribution.
55 //
56 // This member is required.
57 DistributionName *string
58
59 // An object that describes the origin resource for the distribution, such as a
60 // Lightsail instance, bucket, or load balancer.
61 //
62 // The distribution pulls, caches, and serves content from the origin.
63 //
64 // This member is required.
65 Origin *types.InputOrigin
66
67 // An object that describes the cache behavior settings for the distribution.
68 CacheBehaviorSettings *types.CacheSettings
69
70 // An array of objects that describe the per-path cache behavior for the
71 // distribution.
72 CacheBehaviors []types.CacheBehaviorPerPath
73
74 // The name of the SSL/TLS certificate that you want to attach to the distribution.
75 //
76 // Use the [GetCertificates] action to get a list of certificate names that you can specify.
77 //
78 // [GetCertificates]: https://docs.aws.amazon.com/lightsail/2016-11-28/api-reference/API_GetCertificates.html
79 CertificateName *string
80
81 // The IP address type for the distribution.
82 //
83 // The possible values are ipv4 for IPv4 only, and dualstack for IPv4 and IPv6.
84 //
85 // The default value is dualstack .
86 IpAddressType types.IpAddressType
87
88 // The tag keys and optional values to add to the distribution during create.
89 //
90 // Use the TagResource action to tag a resource after it's created.
91 Tags []types.Tag
92
93 // The minimum TLS protocol version for the SSL/TLS certificate.
94 ViewerMinimumTlsProtocolVersion types.ViewerMinimumTlsProtocolVersionEnum
95
96 noSmithyDocumentSerde
97 }
98
99 type CreateDistributionOutput struct {
100
101 // An object that describes the distribution created.
102 Distribution *types.LightsailDistribution
103
104 // An array of objects that describe the result of the action, such as the status
105 // of the request, the timestamp of the request, and the resources affected by the
106 // request.
107 Operation *types.Operation
108
109 // Metadata pertaining to the operation's result.
110 ResultMetadata middleware.Metadata
111
112 noSmithyDocumentSerde
113 }
114
115 func (c *Client) addOperationCreateDistributionMiddlewares(stack *middleware.Stack, options Options) (err error) {
116 if err := stack.Serialize.Add(&setOperationInputMiddleware{}, middleware.After); err != nil {
117 return err
118 }
119 err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateDistribution{}, middleware.After)
120 if err != nil {
121 return err
122 }
123 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateDistribution{}, middleware.After)
124 if err != nil {
125 return err
126 }
127 if err := addProtocolFinalizerMiddlewares(stack, options, "CreateDistribution"); err != nil {
128 return fmt.Errorf("add protocol finalizers: %v", err)
129 }
130
131 if err = addlegacyEndpointContextSetter(stack, options); err != nil {
132 return err
133 }
134 if err = addSetLoggerMiddleware(stack, options); err != nil {
135 return err
136 }
137 if err = addClientRequestID(stack); err != nil {
138 return err
139 }
140 if err = addComputeContentLength(stack); err != nil {
141 return err
142 }
143 if err = addResolveEndpointMiddleware(stack, options); err != nil {
144 return err
145 }
146 if err = addComputePayloadSHA256(stack); err != nil {
147 return err
148 }
149 if err = addRetry(stack, options); err != nil {
150 return err
151 }
152 if err = addRawResponseToMetadata(stack); err != nil {
153 return err
154 }
155 if err = addRecordResponseTiming(stack); err != nil {
156 return err
157 }
158 if err = addSpanRetryLoop(stack, options); err != nil {
159 return err
160 }
161 if err = addClientUserAgent(stack, options); err != nil {
162 return err
163 }
164 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
165 return err
166 }
167 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
168 return err
169 }
170 if err = addSetLegacyContextSigningOptionsMiddleware(stack); err != nil {
171 return err
172 }
173 if err = addTimeOffsetBuild(stack, c); err != nil {
174 return err
175 }
176 if err = addUserAgentRetryMode(stack, options); err != nil {
177 return err
178 }
179 if err = addCredentialSource(stack, options); err != nil {
180 return err
181 }
182 if err = addOpCreateDistributionValidationMiddleware(stack); err != nil {
183 return err
184 }
185 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateDistribution(options.Region), middleware.Before); err != nil {
186 return err
187 }
188 if err = addRecursionDetection(stack); err != nil {
189 return err
190 }
191 if err = addRequestIDRetrieverMiddleware(stack); err != nil {
192 return err
193 }
194 if err = addResponseErrorMiddleware(stack); err != nil {
195 return err
196 }
197 if err = addRequestResponseLogging(stack, options); err != nil {
198 return err
199 }
200 if err = addDisableHTTPSMiddleware(stack, options); err != nil {
201 return err
202 }
203 if err = addInterceptBeforeRetryLoop(stack, options); err != nil {
204 return err
205 }
206 if err = addInterceptAttempt(stack, options); err != nil {
207 return err
208 }
209 if err = addInterceptors(stack, options); err != nil {
210 return err
211 }
212 return nil
213 }
214
215 func newServiceMetadataMiddleware_opCreateDistribution(region string) *awsmiddleware.RegisterServiceMetadata {
216 return &awsmiddleware.RegisterServiceMetadata{
217 Region: region,
218 ServiceID: ServiceID,
219 OperationName: "CreateDistribution",
220 }
221 }
222