[aws_s3] Path to Virtual Hosted-Style workaround with middleware #631
-
I checked #485 and #253 (comment) It looks like Virtual Hosted-Style is already on the roadmap, is there a recommended workaround for the current limitation? any guidance is appreciated example code
result
Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Customizing the middleware on the underlying Smithy client replaces the entire middleware stack, so the built-in credential and endpoint middlewares (among others) from the SDK won't be in the chain unless they're also added during client creation. Fortunately, there's a better way to customize requests now that doesn't require touching middleware. For example: let response = client.head_bucket()
.bucket("example")
.customize()
.await?
.mutate_request(|mut req| {
// change the URI on `req` here
})
.send()
.await?; |
Beta Was this translation helpful? Give feedback.
-
Here's how I ended up generating a signed URL with vhost style: let request_uri = format!("/{key}", key = request.key);
let mut request =
rusoto_core::signature::SignedRequest::new("GET", "s3", &Region::UsEast1, &request_uri);
request.set_hostname(Some(format!("{}.{}", bucket_name, endpoint)));
let non_cdn_uri =
request.generate_presigned_url(&aws_credentials, &Duration::from_secs(5 * 60), false);
let uri = http::Uri::try_from(&non_cdn_uri)?;
let mut parts = uri.into_parts();
*parts.authority.as_mut().unwrap() =
http::uri::Authority::try_from(config.cdn_hostname.clone())?;
let new_uri: http::Uri = parts.try_into()?;
Ok(new_uri.to_string()) My Rust is not the best yet, so I might've messed up some things here but it works! |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Customizing the middleware on the underlying Smithy client replaces the entire middleware stack, so the built-in credential and endpoint middlewares (among others) from the SDK won't be in the chain unless they're also added during client creation.
Fortunately, there's a better way to customize requests now that doesn't require touching middleware. For example: