Skip to content

Conversation

@shubhiscoding
Copy link

Motivation

AWS S3 supports conditional headers (If-Match and If-None-Match) in the CopyObject API to enable atomic copy operations based on the destination object's ETag. LocalStack previously did not support these headers, making it difficult to test applications that rely on conditional copy operations. Fixes #13522

Changes

Implemented support for conditional headers in S3 CopyObject API:

  • Added If-Match header support: Allows copying only if the destination object's ETag matches the specified value
  • Added If-None-Match header support: Allows copying only if the destination object doesn't exist (using * wildcard)
  • Validation logic: Implemented proper error handling for invalid header combinations and unsupported values, matching AWS behavior
  • Precondition checks: Leveraged existing helper functions (object_exists_for_precondition_write and verify_object_equality_precondition_write) to validate conditions before copy operation
    The implementation follows the same pattern as the existing

PutObject conditional header logic.

Tests

Added tests in test_s3_api.py:

  • test_copy_object_if_none_match: Validates If-None-Match: * behavior
    • Successful copy when destination doesn't exist
    • PreconditionFailed error when destination already exists
  • test_copy_object_if_match: Validates If-Match behavior
  • Successful copy when destination ETag matches
  • PreconditionFailed error when ETag doesn't match
  • NoSuchKey error when destination doesn't exist

Related

#13522

Copy link
Contributor

@localstack-bot localstack-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome to LocalStack! Thanks for raising your first Pull Request and landing in your contributions. Our team will reach out with any reviews or feedbacks that we have shortly. We recommend joining our Slack Community and share your PR on the #community channel to share your contributions with us. Please make sure you are following our contributing guidelines and our Code of Conduct.

@localstack-bot
Copy link
Contributor

localstack-bot commented Dec 20, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@shubhiscoding
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

localstack-bot added a commit that referenced this pull request Dec 20, 2025
@bentsku bentsku added aws:s3 Amazon Simple Storage Service semver: patch Non-breaking changes which can be included in patch releases semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes and removed semver: patch Non-breaking changes which can be included in patch releases labels Dec 22, 2025
@bentsku bentsku self-assigned this Dec 22, 2025
Copy link
Contributor

@bentsku bentsku left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contribution!

Unfortunately I can see that the tests are not validated against AWS, and thus not following our contribution guidelines. It would be great if you could validate that.

There is also required changes in the CopyObject operation itself, as these conditions headers are there to prevent race conditions, and we do not have concurrency control in your implementation.

As written in the comments, our contribution expectations are pretty high regarding the S3 service as it is one of the most used and a lot of other services depends on it, we're very careful when modifying its behavior. Let me know if you'd need additional help for this one 👍

edit: forgot to add to both PR, it is holidays season here and we might have some delay in reviewing your changes, and might come back to it in January.

@shubhiscoding
Copy link
Author

shubhiscoding commented Dec 24, 2025

Thanks a lot for your contribution!

Unfortunately I can see that the tests are not validated against AWS, and thus not following our contribution guidelines. It would be great if you could validate that.

There is also required changes in the CopyObject operation itself, as these conditions headers are there to prevent race conditions, and we do not have concurrency control in your implementation.

As written in the comments, our contribution expectations are pretty high regarding the S3 service as it is one of the most used and a lot of other services depends on it, we're very careful when modifying its behavior. Let me know if you'd need additional help for this one 👍

edit: forgot to add to both PR, it is holidays season here and we might have some delay in reviewing your changes, and might come back to it in January.

Hii @bentsku I went through your suggestions and as per my understanding I've made the edits to keep it safe from race conditions (tried mimicking the same logic used in put_object) and also added tests for versioned bucket behavior and also I've ran all those tests against my aws account, I understand the importance of the S3 service, so feel free to suggest any further changes!
Happy Holidays!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws:s3 Amazon Simple Storage Service docs: skip Pull request does not require documentation changes notes: skip Pull request does not have to be mentioned in the release notes semver: minor Non-breaking changes which can be included in minor releases, but not in patch releases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: Support conditional copy operations in S3

3 participants