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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature request: Support conditional copy operations in S3

2 participants