aws_sdk_lightsail/
client.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[derive(Debug)]
3pub(crate) struct Handle {
4    pub(crate) conf: crate::Config,
5    #[allow(dead_code)] // unused when a service does not provide any operations
6    pub(crate) runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
7}
8
9/// Client for Amazon Lightsail
10///
11/// Client for invoking operations on Amazon Lightsail. Each operation on Amazon Lightsail is a method on this
12/// this struct. `.send()` MUST be invoked on the generated operations to dispatch the request to the service.
13/// ## Constructing a `Client`
14///
15/// A [`Config`] is required to construct a client. For most use cases, the [`aws-config`]
16/// crate should be used to automatically resolve this config using
17/// [`aws_config::load_from_env()`], since this will resolve an [`SdkConfig`] which can be shared
18/// across multiple different AWS SDK clients. This config resolution process can be customized
19/// by calling [`aws_config::from_env()`] instead, which returns a [`ConfigLoader`] that uses
20/// the [builder pattern] to customize the default config.
21///
22/// In the simplest case, creating a client looks as follows:
23/// ```rust,no_run
24/// # async fn wrapper() {
25/// let config = aws_config::load_from_env().await;
26/// let client = aws_sdk_lightsail::Client::new(&config);
27/// # }
28/// ```
29///
30/// Occasionally, SDKs may have additional service-specific values that can be set on the [`Config`] that
31/// is absent from [`SdkConfig`], or slightly different settings for a specific client may be desired.
32/// The [`Builder`](crate::config::Builder) struct implements `From<&SdkConfig>`, so setting these specific settings can be
33/// done as follows:
34///
35/// ```rust,no_run
36/// # async fn wrapper() {
37/// let sdk_config = ::aws_config::load_from_env().await;
38/// let config = aws_sdk_lightsail::config::Builder::from(&sdk_config)
39/// # /*
40///     .some_service_specific_setting("value")
41/// # */
42///     .build();
43/// # }
44/// ```
45///
46/// See the [`aws-config` docs] and [`Config`] for more information on customizing configuration.
47///
48/// _Note:_ Client construction is expensive due to connection thread pool initialization, and should
49/// be done once at application start-up.
50///
51/// [`Config`]: crate::Config
52/// [`ConfigLoader`]: https://docs.rs/aws-config/*/aws_config/struct.ConfigLoader.html
53/// [`SdkConfig`]: https://docs.rs/aws-config/*/aws_config/struct.SdkConfig.html
54/// [`aws-config` docs]: https://docs.rs/aws-config/*
55/// [`aws-config`]: https://crates.io/crates/aws-config
56/// [`aws_config::from_env()`]: https://docs.rs/aws-config/*/aws_config/fn.from_env.html
57/// [`aws_config::load_from_env()`]: https://docs.rs/aws-config/*/aws_config/fn.load_from_env.html
58/// [builder pattern]: https://rust-lang.github.io/api-guidelines/type-safety.html#builders-enable-construction-of-complex-values-c-builder
59/// # Using the `Client`
60///
61/// A client has a function for every operation that can be performed by the service.
62/// For example, the [`AllocateStaticIp`](crate::operation::allocate_static_ip) operation has
63/// a [`Client::allocate_static_ip`], function which returns a builder for that operation.
64/// The fluent builder ultimately has a `send()` function that returns an async future that
65/// returns a result, as illustrated below:
66///
67/// ```rust,ignore
68/// let result = client.allocate_static_ip()
69///     .static_ip_name("example")
70///     .send()
71///     .await;
72/// ```
73///
74/// The underlying HTTP requests that get made by this can be modified with the `customize_operation`
75/// function on the fluent builder. See the [`customize`](crate::client::customize) module for more
76/// information.
77#[derive(::std::clone::Clone, ::std::fmt::Debug)]
78pub struct Client {
79    handle: ::std::sync::Arc<Handle>,
80}
81
82impl Client {
83    /// Creates a new client from the service [`Config`](crate::Config).
84    ///
85    /// # Panics
86    ///
87    /// This method will panic in the following cases:
88    ///
89    /// - Retries or timeouts are enabled without a `sleep_impl` configured.
90    /// - Identity caching is enabled without a `sleep_impl` and `time_source` configured.
91    /// - No `behavior_version` is provided.
92    ///
93    /// The panic message for each of these will have instructions on how to resolve them.
94    #[track_caller]
95    pub fn from_conf(conf: crate::Config) -> Self {
96        let handle = Handle {
97            conf: conf.clone(),
98            runtime_plugins: crate::config::base_client_runtime_plugins(conf),
99        };
100        if let Err(err) = Self::validate_config(&handle) {
101            panic!("Invalid client configuration: {err}");
102        }
103        Self {
104            handle: ::std::sync::Arc::new(handle),
105        }
106    }
107
108    /// Returns the client's configuration.
109    pub fn config(&self) -> &crate::Config {
110        &self.handle.conf
111    }
112
113    fn validate_config(handle: &Handle) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
114        let mut cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
115        handle
116            .runtime_plugins
117            .apply_client_configuration(&mut cfg)?
118            .validate_base_client_config(&cfg)?;
119        Ok(())
120    }
121}
122
123impl Client {
124    /// Creates a new client from an [SDK Config](::aws_types::sdk_config::SdkConfig).
125    ///
126    /// # Panics
127    ///
128    /// - This method will panic if the `sdk_config` is missing an async sleep implementation. If you experience this panic, set
129    ///   the `sleep_impl` on the Config passed into this function to fix it.
130    /// - This method will panic if the `sdk_config` is missing an HTTP connector. If you experience this panic, set the
131    ///   `http_connector` on the Config passed into this function to fix it.
132    /// - This method will panic if no `BehaviorVersion` is provided. If you experience this panic, set `behavior_version` on the Config or enable the `behavior-version-latest` Cargo feature.
133    #[track_caller]
134    pub fn new(sdk_config: &::aws_types::sdk_config::SdkConfig) -> Self {
135        Self::from_conf(sdk_config.into())
136    }
137}
138
139mod allocate_static_ip;
140
141mod attach_certificate_to_distribution;
142
143mod attach_disk;
144
145mod attach_instances_to_load_balancer;
146
147mod attach_load_balancer_tls_certificate;
148
149mod attach_static_ip;
150
151mod close_instance_public_ports;
152
153mod copy_snapshot;
154
155mod create_bucket;
156
157mod create_bucket_access_key;
158
159mod create_certificate;
160
161mod create_cloud_formation_stack;
162
163mod create_contact_method;
164
165mod create_container_service;
166
167mod create_container_service_deployment;
168
169mod create_container_service_registry_login;
170
171mod create_disk;
172
173mod create_disk_from_snapshot;
174
175mod create_disk_snapshot;
176
177mod create_distribution;
178
179mod create_domain;
180
181mod create_domain_entry;
182
183mod create_gui_session_access_details;
184
185mod create_instance_snapshot;
186
187mod create_instances;
188
189mod create_instances_from_snapshot;
190
191mod create_key_pair;
192
193mod create_load_balancer;
194
195mod create_load_balancer_tls_certificate;
196
197mod create_relational_database;
198
199mod create_relational_database_from_snapshot;
200
201mod create_relational_database_snapshot;
202
203/// Operation customization and supporting types.
204///
205/// The underlying HTTP requests made during an operation can be customized
206/// by calling the `customize()` method on the builder returned from a client
207/// operation call. For example, this can be used to add an additional HTTP header:
208///
209/// ```ignore
210/// # async fn wrapper() -> ::std::result::Result<(), aws_sdk_lightsail::Error> {
211/// # let client: aws_sdk_lightsail::Client = unimplemented!();
212/// use ::http::header::{HeaderName, HeaderValue};
213///
214/// let result = client.allocate_static_ip()
215///     .customize()
216///     .mutate_request(|req| {
217///         // Add `x-example-header` with value
218///         req.headers_mut()
219///             .insert(
220///                 HeaderName::from_static("x-example-header"),
221///                 HeaderValue::from_static("1"),
222///             );
223///     })
224///     .send()
225///     .await;
226/// # }
227/// ```
228pub mod customize;
229
230mod delete_alarm;
231
232mod delete_auto_snapshot;
233
234mod delete_bucket;
235
236mod delete_bucket_access_key;
237
238mod delete_certificate;
239
240mod delete_contact_method;
241
242mod delete_container_image;
243
244mod delete_container_service;
245
246mod delete_disk;
247
248mod delete_disk_snapshot;
249
250mod delete_distribution;
251
252mod delete_domain;
253
254mod delete_domain_entry;
255
256mod delete_instance;
257
258mod delete_instance_snapshot;
259
260mod delete_key_pair;
261
262mod delete_known_host_keys;
263
264mod delete_load_balancer;
265
266mod delete_load_balancer_tls_certificate;
267
268mod delete_relational_database;
269
270mod delete_relational_database_snapshot;
271
272mod detach_certificate_from_distribution;
273
274mod detach_disk;
275
276mod detach_instances_from_load_balancer;
277
278mod detach_static_ip;
279
280mod disable_add_on;
281
282mod download_default_key_pair;
283
284mod enable_add_on;
285
286mod export_snapshot;
287
288mod get_active_names;
289
290mod get_alarms;
291
292mod get_auto_snapshots;
293
294mod get_blueprints;
295
296mod get_bucket_access_keys;
297
298mod get_bucket_bundles;
299
300mod get_bucket_metric_data;
301
302mod get_buckets;
303
304mod get_bundles;
305
306mod get_certificates;
307
308mod get_cloud_formation_stack_records;
309
310mod get_contact_methods;
311
312mod get_container_api_metadata;
313
314mod get_container_images;
315
316mod get_container_log;
317
318mod get_container_service_deployments;
319
320mod get_container_service_metric_data;
321
322mod get_container_service_powers;
323
324mod get_container_services;
325
326mod get_cost_estimate;
327
328mod get_disk;
329
330mod get_disk_snapshot;
331
332mod get_disk_snapshots;
333
334mod get_disks;
335
336mod get_distribution_bundles;
337
338mod get_distribution_latest_cache_reset;
339
340mod get_distribution_metric_data;
341
342mod get_distributions;
343
344mod get_domain;
345
346mod get_domains;
347
348mod get_export_snapshot_records;
349
350mod get_instance;
351
352mod get_instance_access_details;
353
354mod get_instance_metric_data;
355
356mod get_instance_port_states;
357
358mod get_instance_snapshot;
359
360mod get_instance_snapshots;
361
362mod get_instance_state;
363
364mod get_instances;
365
366mod get_key_pair;
367
368mod get_key_pairs;
369
370mod get_load_balancer;
371
372mod get_load_balancer_metric_data;
373
374mod get_load_balancer_tls_certificates;
375
376mod get_load_balancer_tls_policies;
377
378mod get_load_balancers;
379
380mod get_operation;
381
382mod get_operations;
383
384mod get_operations_for_resource;
385
386mod get_regions;
387
388mod get_relational_database;
389
390mod get_relational_database_blueprints;
391
392mod get_relational_database_bundles;
393
394mod get_relational_database_events;
395
396mod get_relational_database_log_events;
397
398mod get_relational_database_log_streams;
399
400mod get_relational_database_master_user_password;
401
402mod get_relational_database_metric_data;
403
404mod get_relational_database_parameters;
405
406mod get_relational_database_snapshot;
407
408mod get_relational_database_snapshots;
409
410mod get_relational_databases;
411
412mod get_setup_history;
413
414mod get_static_ip;
415
416mod get_static_ips;
417
418mod import_key_pair;
419
420mod is_vpc_peered;
421
422mod open_instance_public_ports;
423
424mod peer_vpc;
425
426mod put_alarm;
427
428mod put_instance_public_ports;
429
430mod reboot_instance;
431
432mod reboot_relational_database;
433
434mod register_container_image;
435
436mod release_static_ip;
437
438mod reset_distribution_cache;
439
440mod send_contact_method_verification;
441
442mod set_ip_address_type;
443
444mod set_resource_access_for_bucket;
445
446mod setup_instance_https;
447
448mod start_gui_session;
449
450mod start_instance;
451
452mod start_relational_database;
453
454mod stop_gui_session;
455
456mod stop_instance;
457
458mod stop_relational_database;
459
460mod tag_resource;
461
462mod test_alarm;
463
464mod unpeer_vpc;
465
466mod untag_resource;
467
468mod update_bucket;
469
470mod update_bucket_bundle;
471
472mod update_container_service;
473
474mod update_distribution;
475
476mod update_distribution_bundle;
477
478mod update_domain_entry;
479
480mod update_instance_metadata_options;
481
482mod update_load_balancer_attribute;
483
484mod update_relational_database;
485
486mod update_relational_database_parameters;