Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

S3 conditional GETs should return an easier to manage error #363

Closed
2 tasks
jmklix opened this issue Oct 3, 2022 · 3 comments
Closed
2 tasks

S3 conditional GETs should return an easier to manage error #363

jmklix opened this issue Oct 3, 2022 · 3 comments
Assignees
Labels
feature-request New feature or request s3 service-api This issue pertains to the AWS API

Comments

@jmklix
Copy link
Member

jmklix commented Oct 3, 2022

Transfered from awslabs/aws-sdk-rust: awslabs/aws-sdk-rust#534

Describe the feature

If one wants to perform a conditional GET from S3, it seems the current pattern is:

    let client = Client::new(&shared_config);
    let resp1 = client
        .get_object()
        .bucket(bucket.to_string())
        .key(from.to_string())
        .set_if_modified_since(last_modified)
        .send()
        .await;

    if let Err(e) = resp1 {
        match e {
            SdkError::ServiceError {
                err: _,
                raw: ref ra,
            } => {
                if ra.http().status() == 304 {
                    tracing::info!("not modified");
                    return Ok(last_modified);
                }
                return Err(e.into());
            }
            _ => return Err(e.into()),
        }
    } else {
        let mut resp = resp1?;
        let tmp = to.as_ref().to_path_buf().with_extension("tmp");
        if let Some(parent) = to.as_ref().parent() {
            tokio::fs::create_dir_all(parent).await?;
        }
        {
            let mut file = File::create(tmp.as_path()).await?;
            while let Some(bytes) = resp.body.next().await {
                let bytes = bytes?;
                file.write_all(&bytes).await?;
            }
            file.flush().await?;
        }
        tokio::fs::rename(tmp, to).await?;
        info!("Downloaded");
        Ok(resp.last_modified().cloned())
    }

Use Case

More intuitively handle the conditional S3 GET. Maybe there's already some way to handle this that I missed.

Proposed Solution

It seems to me that perhaps ServiceError should provide an API to quickly determine if it's a NotModified error, also perhaps adding NotModified variant to GetObjectErrorKind since right now this falls under Unhandled which requires to go deeper into the raw Response.

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

A note for the community

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue, please leave a comment
@jmklix jmklix added service-api This issue pertains to the AWS API s3 labels Oct 3, 2022
@jmklix jmklix self-assigned this Oct 3, 2022
@jmklix
Copy link
Member Author

jmklix commented Oct 3, 2022

P76487895

@jmklix
Copy link
Member Author

jmklix commented Oct 30, 2024

I reached out to the S3 team and shared your use case to gather more insights on your behalf. Since this issue isn’t directly actionable by the SDK team, and this repository is dedicated to SDK-related issues, I'll go ahead and close this ticket. If you have access to AWS support through the Developer Console, please consider creating a support ticket and referencing the ticket ID I shared above to receive updates directly from the service team. Otherwise, you can keep an eye on our release notes for news on when this is resolved.

@jmklix jmklix closed this as completed Oct 30, 2024
Copy link

This issue is now closed.

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request New feature or request s3 service-api This issue pertains to the AWS API
Projects
None yet
Development

No branches or pull requests

1 participant