awslabs / aws-sdk-rust

AWS SDK for the Rust Programming Language
https://awslabs.github.io/aws-sdk-rust/
Apache License 2.0
3.01k stars 248 forks source link

S3 CreateBucketOutput location() returns a URL rather than the bucket name #732

Open keithsharp opened 1 year ago

keithsharp commented 1 year ago

Describe the issue

The documentation states location() returns: "A forward slash followed by the name of the bucket.". This should be updated to match the current behavior when creating an S3 bucket:

let constraint = BucketLocationConstraint::from("eu-west-1");
let cfg = CreateBucketConfiguration::builder()
    .location_constraint(constraint)
    .build();

let resp = client.create_bucket()
    .bucket("my-test-bucket")
    .create_bucket_configuration(cfg)
    .send()
    .await?;

println!("{}", resp.location().unwrap());

The output is:

http://my-test-bucket.s3.amazonaws.com/

Links

https://docs.rs/aws-sdk-s3/latest/aws_sdk_s3/output/struct.CreateBucketOutput.html#method.location

Velfi commented 1 year ago

@keithsharp Thanks for reporting this.

@jmklix This looks like a documentation issue for S3. Have other SDKs received reports of this?

Looking at the relevant deserialization code, we're not doing anything to format the location:

pub(crate) fn deser_header_create_bucket_create_bucket_output_location(
    header_map: &http::HeaderMap,
) -> std::result::Result<
    std::option::Option<std::string::String>,
    aws_smithy_http::header::ParseError,
> {
    let headers = header_map.get_all("Location").iter();
    aws_smithy_http::header::one_or_none(headers)
}
ysaito1001 commented 1 year ago

To add, this behavior is reproducible when a bucket configuration is specified. In other words, if we comment out the following line

let resp = client.create_bucket()
    .bucket("my-test-bucket")
    // .create_bucket_configuration(cfg)
    .send()
    .await?;

then resp.location().unwrap() returns /my-test-bucket.

Specifying a bucket configuration adds the following to the request body

<CreateBucketConfiguration xmlns=\"http://s3.amazonaws.com/doc/2006-03-01/\"><LocationConstraint>eu-west-1</LocationConstraint></CreateBucketConfiguration>

and changes S3's behavior of returning the bucket location: http://my-test-bucket.s3.amazonaws.com/.