Skip to content

bug: S3 CopyObject fails with an HTTP 412 error when a valid x-amz-copy-source-if-modified-since header value is provided #13331

@LowCostCustoms

Description

@LowCostCustoms

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Calling the S3 CopyObject operation for an existing source object with a valid x-amz-copy-source-if-modified-since header value causes the request to fail with an HTTP 412 status. The request however, doesn't fail if called against a real AWS S3 bucket.

Expected Behavior

No response

How are you starting LocalStack?

With a docker run command

Steps To Reproduce

How are you starting localstack (e.g., bin/localstack command, arguments, or docker-compose.yml)

docker run --rm -it -p 4566:4566 localstack/localstack:s3-latest

Client commands (e.g., AWS SDK code snippet, or sequence of "awslocal" commands)

Bucket setup snippet:

import boto3
import botocore.config

bucket = "testbucket"

client = boto3.client(
    "s3",
    endpoint_url="http://localhost:4566",
    aws_access_key_id="112233445566",
    aws_secret_access_key="test",
    config=botocore.config.Config(signature_version="s3v4"),
    verify=False,
)

client.create_bucket(Bucket=bucket)
client.put_bucket_versioning(
    Bucket=bucket,
    VersioningConfiguration={
        "Status": "Enabled",
    },
)

Bug reproduction script:

import boto3
import botocore.config

bucket = "testbucket"
source_key = "sourcekey"
target_key = "target"

client = boto3.client(
    "s3",
    endpoint_url="http://localhost:4566",
    aws_access_key_id="112233445566",
    aws_secret_access_key="test",
    config=botocore.config.Config(signature_version="s3v4"),
    verify=False,
)

client.put_object(Bucket=bucket, Key=source_key, Body=b"stuff")

source_properties = client.head_object(Bucket=bucket, Key=source_key)

client.copy_object(
    Bucket=bucket,
    Key=target_key,
    CopySource={
        "Bucket": bucket,
        "Key": source_key,
    },
    CopySourceIfUnmodifiedSince=source_properties["LastModified"],
)

Environment

- OS: Linux NV-F4SHWL3 6.6.87.2-microsoft-standard-WSL2 #1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
- LocalStack: localstack/localstack:s3-latest
  LocalStack version: 4.10.1.dev1
  LocalStack Docker image sha: cea0c7dc0edc
  LocalStack build date: 2025-10-30
  LocalStack build git hash: 6f9927619

Anything else?

No response

Metadata

Metadata

Assignees

Labels

aws:s3Amazon Simple Storage Servicestatus: backlogTriaged but not yet being worked ontype: bugBug report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions