-
I'm a little new to rust. i was wondering why the mentioned values are &'static because it made it challenging changing their values while building aws_endpoint::Partition. fn setup_s3_client(endpoint_resolver: aws_endpoint::PartitionResolver, region: &'static str) -> s3::Client {
let conf = s3::Config::builder()
.region(s3::Region::new(region))
.endpoint_resolver(endpoint_resolver)
.build();
s3::Client::from_conf(conf)
}
fn setup_sqs_client(endpoint_resolver: aws_endpoint::PartitionResolver, region: &'static str) -> sqs::Client {
let conf = sqs::Config::builder()
.region(s3::Region::new(region))
.endpoint_resolver(endpoint_resolver)
.build();
sqs::Client::from_conf(conf)
}
fn build_resolver(region: &'static str, aws_host: &'static str) -> aws_endpoint::PartitionResolver {
let p = aws_endpoint::Partition::builder()
.id("part-id-1")
.region_regex(r#"^(eu)-\w+-\d+$"#)
.partition_endpoint("")
.regionalized(aws_endpoint::partition::Regionalized::Regionalized)
.default_endpoint(aws_endpoint::partition::endpoint::Metadata {
uri_template: aws_host,
protocol: aws_endpoint::partition::endpoint::Protocol::Http,
credential_scope: aws_endpoint::CredentialScope::builder()
.region(region)
.build(),
signature_versions: aws_endpoint::partition::endpoint::SignatureVersion::V4,
})
.endpoint(
region,
aws_endpoint::partition::endpoint::Metadata {
uri_template: aws_host,
protocol: aws_endpoint::partition::endpoint::Protocol::Http,
credential_scope: aws_endpoint::CredentialScope::builder()
.region(region)
.build(),
signature_versions: aws_endpoint::partition::endpoint::SignatureVersion::V4,
},
)
.build()
.unwrap();
aws_endpoint::PartitionResolver::new(p, vec![])
}
pub struct QueueProcessor {
app_config: AppEnvConfig,
sqs_client: &'static sqs::Client,
s3_client: &'static s3::Client
}
#[derive(Deserialize, Debug)]
pub struct AppEnvConfig {
pub aws_default_region: String,
pub aws_host: String,
}
#[tokio::main]
async fn main() -> Result<()> {
// ...
let app_config = envy::from_env::<AppEnvConfig>().unwrap();
let aws_default_region = app_config.aws_default_region.to_owned();
let aws_host = app_config.aws_host.to_owned();
let aws_host_str = Box::leak(aws_host.into_boxed_str());
let region: &'static str = Box::leak(aws_default_region.into_boxed_str());
let sqs_client = Box::new(setup_sqs_client(build_resolver(region, aws_host_str), region));
let s3_client= Box::new(setup_s3_client(build_resolver(region, aws_host_str), region));
let queue_processor = QueueProcessor::new(app_config, Box::leak(sqs_client), Box::leak(sqs_client));
// some other code...
} i guess because they are static (region and uri_template) , i can't easily wrap |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hello! Thanks for reaching out! Can your give a little bit more detail about why you're setting a custom endpoint resolver? An endpoint resolver should be generated automatically for the SDK clients.
It's also worth noting that the |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Hello! Thanks for reaching out! Can your give a little bit more detail about why you're setting a custom endpoint resolver? An endpoint resolver should be generated automatically for the SDK clients.
It's also worth noting that the
Client
objects already use an internal arc so they should be cheap clones.