You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As part of ropensci/gittargets#6, I am trying to programmatically revert an object in an S3 bucket to an earlier version. From reading https://docs.aws.amazon.com/AmazonS3/latest/userguide/RestoringPreviousVersions.html, it looks like copying the object to itself (old version to current version) is the most efficient way to go. But I do not know how to use HTTP/REST headers, and I do not know how to select the old version of the object. Is there a header I can specify or a request I can submit to make this work in R with aws.s3?
library(aws.s3)
library(uuid)
bucket<- UUIDgenerate()
put_bucket(bucket)
#> [1] TRUE
put_versioning(bucket, "Enabled")
#> NULL
s3HTTP(
verb="GET",
bucket=bucket,
query=list(versioning="")
)[1]
#> [1] "Enabled"# old versiontmp<- tempfile()
writeLines("old", tmp)
out<- put_object(
file=tmp,
object="object",
bucket=bucket
)
version_old<- get_versions(bucket)$Version$VersionId# new versiontmp<- tempfile()
writeLines("new", tmp)
out<- put_object(
file=tmp,
object="object",
bucket=bucket
)
version_new<- get_versions(bucket)$Version$VersionId# Should be "new".
get_object("object", bucket, as="text")
#> No encoding supplied: defaulting to UTF-8.#> [1] "new\n"# Should be "old". Why is it "new"?
get_object(
"object",
bucket,
as="text",
headers=list(versionId=version_old)
)
#> No encoding supplied: defaulting to UTF-8.#> [1] "new\n"# Is this how I revert to the old version?out<- copy_object(
from_object="object",
to_object="object",
from_bucket=bucket,
to_bucket=bucket,
headers=list(versionId=version_old)
)
#> List of 4#> $ Code : chr "InvalidRequest"#> $ Message : chr "This copy request is illegal because it is trying to copy an object to itself without changing the object's met"| __truncated__#> $ RequestId: chr "JNVJ3H7B0B1KDFB3"#> $ HostId : chr "Slte9SnTL0Xralznix6k93ez0Ja/8ij+pIqEMZmvq0zmfFPUdeFXWewWh80Ky/kViQ1ZhlVh44U="#> - attr(*, "headers")=List of 7#> ..$ x-amz-request-id : chr "JNVJ3H7B0B1KDFB3"#> ..$ x-amz-id-2 : chr "Slte9SnTL0Xralznix6k93ez0Ja/8ij+pIqEMZmvq0zmfFPUdeFXWewWh80Ky/kViQ1ZhlVh44U="#> ..$ content-type : chr "application/xml"#> ..$ transfer-encoding: chr "chunked"#> ..$ date : chr "Mon, 22 Nov 2021 19:13:59 GMT"#> ..$ server : chr "AmazonS3"#> ..$ connection : chr "close"#> ..- attr(*, "class")= chr [1:2] "insensitive" "list"#> - attr(*, "class")= chr "aws_error"#> - attr(*, "request_canonical")= chr "PUT\n/66553a84-0282-4ab8-87a5-e37a09aafcff/object\n\nhost:s3.amazonaws.com\nversionid:so6dk_b_t7CcEcbjj3Ok14sP4"| __truncated__#> - attr(*, "request_string_to_sign")= chr "AWS4-HMAC-SHA256\n20211122T191359Z\n20211122/us-east-1/s3/aws4_request\n8788609957ebcf0ab01338ed90ca4cd74e41747"| __truncated__#> - attr(*, "request_signature")= chr "AWS4-HMAC-SHA256 Credential=AKIA5IZZ3SMAULVNHKWK/20211122/us-east-1/s3/aws4_request,SignedHeaders=host;versioni"| __truncated__#> NULL#> Error in parse_aws_s3_response(r, Sig, verbose = verbose): Bad Request (HTTP 400).
As part of ropensci/gittargets#6, I am trying to programmatically revert an object in an S3 bucket to an earlier version. From reading https://docs.aws.amazon.com/AmazonS3/latest/userguide/RestoringPreviousVersions.html, it looks like copying the object to itself (old version to current version) is the most efficient way to go. But I do not know how to use HTTP/REST headers, and I do not know how to select the old version of the object. Is there a header I can specify or a request I can submit to make this work in R with
aws.s3
?Created on 2021-11-22 by the reprex package (v2.0.1)
Session info
The text was updated successfully, but these errors were encountered: