ds_common_aws_rs_lib/client.rs
1//! AWS Service module.
2//!
3//! This module provides a unified AWS service that manages shared clients
4//! and provides specialized services for different AWS services.
5
6use aws_config::meta::region::RegionProviderChain;
7use aws_config::SdkConfig;
8
9use crate::error::{Error, Result};
10
11/// Main AWS client that manages shared configuration and clients
12///
13/// This client provides a unified way to access AWS services with shared
14/// configuration and client management for better performance and resource usage.
15pub struct AwsClient {
16 config: SdkConfig,
17}
18
19impl AwsClient {
20 /// Create a new AWS client with default configuration
21 ///
22 /// # Returns
23 ///
24 /// Returns a new AwsClient instance, or an error if the operation fails.
25 pub async fn new() -> Result<Self, Error> {
26 let config = aws_config::defaults(aws_config::BehaviorVersion::latest())
27 .region(RegionProviderChain::default_provider().or_else("eu-north-1"))
28 .load()
29 .await;
30 Ok(Self { config })
31 }
32
33 /// Create a new AWS client with a custom configuration
34 ///
35 /// # Arguments
36 ///
37 /// * `config` - The AWS SDK configuration to use
38 ///
39 /// # Returns
40 ///
41 /// Returns a new AwsClient instance with the provided configuration.
42 pub fn with_config(config: SdkConfig) -> Self {
43 Self { config }
44 }
45
46 /// Get the underlying SDK configuration
47 ///
48 /// # Returns
49 ///
50 /// Returns a reference to the SDK configuration.
51 pub fn config(&self) -> &SdkConfig {
52 &self.config
53 }
54
55 /// Create an SQS service using the shared configuration
56 ///
57 /// # Returns
58 ///
59 /// Returns a new SqsService instance using the shared configuration.
60 #[cfg(feature = "sqs")]
61 pub fn sqs(&self) -> crate::sqs::SqsService {
62 crate::sqs::SqsService::with_config(&self.config)
63 }
64
65 /// Create an SSM service using the shared configuration
66 ///
67 /// # Returns
68 ///
69 /// Returns a new SsmService instance using the shared configuration.
70 #[cfg(feature = "ssm")]
71 pub fn ssm(&self) -> crate::ssm::SsmService {
72 crate::ssm::SsmService::with_config(&self.config)
73 }
74}