diff --git a/moto/s3/responses.py b/moto/s3/responses.py index 5285cd975..f10bd6500 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -1319,7 +1319,10 @@ class S3Response(BaseResponse): response_headers["x-amz-version-id"] = key.version_id if key.storage_class in ARCHIVE_STORAGE_CLASSES: - raise InvalidObjectState(storage_class=key.storage_class) + if 'ongoing-request="false"' not in key.response_dict.get( + "x-amz-restore", "" + ): + raise InvalidObjectState(storage_class=key.storage_class) if if_unmodified_since: if_unmodified_since = str_to_rfc_1123_datetime(if_unmodified_since) if key.last_modified.replace(microsecond=0) > if_unmodified_since: diff --git a/tests/test_s3/test_s3_storageclass.py b/tests/test_s3/test_s3_storageclass.py index 4c71a6b33..c0fa60cd6 100644 --- a/tests/test_s3/test_s3_storageclass.py +++ b/tests/test_s3/test_s3_storageclass.py @@ -231,8 +231,18 @@ def test_s3_copy_object_for_deep_archive_storage_class_restored(): Bucket="Bucket", Key="First_Object", Body="Body", StorageClass="DEEP_ARCHIVE" ) + with pytest.raises(ClientError) as exc: + s3.get_object(Bucket="Bucket", Key="First_Object") + err = exc.value.response["Error"] + err["Code"].should.equal("InvalidObjectState") + err["Message"].should.equal( + "The operation is not valid for the object's storage class" + ) + err["StorageClass"].should.equal("DEEP_ARCHIVE") + s3.create_bucket(Bucket="Bucket2") s3.restore_object(Bucket="Bucket", Key="First_Object", RestoreRequest={"Days": 123}) + s3.get_object(Bucket="Bucket", Key="First_Object") s3.copy_object( CopySource={"Bucket": "Bucket", "Key": "First_Object"},