Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S3 restore object from intelligent tiering requires empty RestoreRequest - how to pass along? #849

Open
FMKerckhof opened this issue Dec 9, 2024 · 9 comments
Labels
bug 🐞 Something isn't working

Comments

@FMKerckhof
Copy link

Dear, I am trying to initiate an object restore from an object in Intelligent Tiering Archive Tier (https://awscli.amazonaws.com/v2/documentation/api/latest/reference/s3api/restore-object.html) with s3$restore_object (https://www.paws-r-sdk.com/docs/s3_restore_object/)

However, I am running into trouble to pass along an empty JSON for the --restore-request (RestoreRequest) list. As per AWS documentation, for this type of restore an empty JSON {} has to be passed along.

For example, in the terminal with AWS CLI (S3 API) the following command initiates the restore just fine:

aws s3api restore-object --bucket bucketname --key objectname --restore-request '{}'

However, I tried the below iterations in R with several variations without much success

library(paws)

s3con <- paws::s3()

s3con$restore_object(Bucket = bucket_with_restore_objs,
                         Key =   key_to_restore,
                         RestoreRequest = list("{}"))
# Error: MissingRequestBodyError (HTTP 400). Request Body is empty

s3con$restore_object(Bucket = bucket_with_restore_objs,
                         Key =   key_to_restore)
# Error: MissingRequestBodyError (HTTP 400). Request Body is empty

s3con$restore_object(Bucket = bucket_with_restore_objs,
                         Key =   key_to_restore,
                         RestoreRequest = list(""))
# Error: MissingRequestBodyError (HTTP 400). Request Body is empty

s3con$restore_object(Bucket = bucket_with_restore_objs,
                         Key =   key_to_restore,
                         RestoreRequest = list())
# Error: MissingRequestBodyError (HTTP 400). Request Body is empty

s3con$restore_object(Bucket = bucket_with_restore_objs,
                         Key =   key_to_restore,
                         RestoreRequest = "")
# Error: MissingRequestBodyError (HTTP 400). Request Body is empty

s3con$restore_object(Bucket = bucket_with_restore_objs,
                         Key =   key_to_restore,
                         RestoreRequest = "{}")
# Error: MissingRequestBodyError (HTTP 400). Request Body is empty

I tried to look a bit into JSON conversion/handlers (https://github.com/paws-r/paws/blob/main/paws.common/R/handlers_core.R) but I also cannot succeed myself to get the required output from jsonlite::toJSON or jsonlite::serializeJSON.

Any pointers in how I could tell paws to pass along --restore-request '{}' to the object restore operation from the S3 API are warmly welcome.

@DyfanJones
Copy link
Member

Hi sorry about that, what version of paws.common are you using?

@FMKerckhof
Copy link
Author

@DyfanJones : I am using paws.common 0.7.7 on R 4.4.0 - for reference I post my session_info below

─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.4.0 (2024-04-24)
 os       Ubuntu 22.04.5 LTS
 system   x86_64, linux-gnu
 ui       RStudio
 language (EN)
 collate  C.UTF-8
 ctype    C.UTF-8
 tz       Etc/UTC
 date     2024-12-10
 rstudio  2024.09.1+394.pro7 Cranberry Hibiscus (server)
 pandoc   3.2 @ /usr/lib/rstudio-server/bin/quarto/bin/tools/x86_64/ (via rmarkdown)

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package       * version    date (UTC) lib source
 abind           1.4-8      2024-09-12 [1] CRAN (R 4.4.0)
 aws.s3          0.3.21     2020-04-07 [2] CRAN (R 4.4.0)
 aws.signature   0.6.0      2020-06-01 [2] CRAN (R 4.4.0)
 base64enc       0.1-3      2015-07-28 [2] CRAN (R 4.4.0)
 Biobase         2.66.0     2024-10-29 [1] RSPM (R 4.4.0)
 BiocGenerics    0.52.0     2024-10-29 [1] RSPM (R 4.4.0)
 BiocManager   * 1.30.25    2024-08-28 [1] CRAN (R 4.4.0)
 bitops          1.0-9      2024-10-03 [1] CRAN (R 4.4.0)
 boot            1.3-31     2024-08-28 [1] CRAN (R 4.4.0)
 cachem          1.1.0      2024-05-16 [2] CRAN (R 4.4.0)
 Cairo           1.6-2      2023-11-28 [2] CRAN (R 4.4.0)
 car             3.1-3      2024-09-27 [1] CRAN (R 4.4.0)
 carData         3.0-5      2022-01-06 [2] CRAN (R 4.4.0)
 caTools         1.18.3     2024-09-04 [1] CRAN (R 4.4.0)
 class           7.3-22     2023-05-03 [2] CRAN (R 4.4.0)
 cli             3.6.3      2024-06-21 [1] CRAN (R 4.4.0)
 cluster         2.1.6      2023-12-01 [2] CRAN (R 4.4.0)
 codetools       0.2-20     2024-03-31 [2] CRAN (R 4.4.0)
 colorspace      2.1-1      2024-07-26 [1] CRAN (R 4.4.0)
 config          0.3.2      2023-08-30 [2] CRAN (R 4.4.0)
 connectapi      0.4.0      2024-11-08 [1] CRAN (R 4.4.0)
 crayon          1.5.3      2024-06-20 [1] RSPM (R 4.4.0)
 curl            6.0.1      2024-11-14 [1] CRAN (R 4.4.0)
 data.table      1.16.2     2024-10-10 [1] CRAN (R 4.4.0)
 deldir          2.0-4      2024-02-28 [2] CRAN (R 4.4.0)
 devtools        2.4.5      2022-10-11 [1] CRAN (R 4.4.0)
 digest          0.6.37     2024-08-19 [1] CRAN (R 4.4.0)
 dplyr           1.1.4      2023-11-17 [2] CRAN (R 4.4.0)
 ellipsis        0.3.2      2021-04-29 [2] CRAN (R 4.4.0)
 evaluate        1.0.1      2024-10-10 [1] CRAN (R 4.4.0)
 fansi           1.0.6      2023-12-08 [2] CRAN (R 4.4.0)
 fastmap         1.2.0      2024-05-15 [2] CRAN (R 4.4.0)
 foreach       * 1.5.2      2022-02-02 [2] CRAN (R 4.4.0)
 Formula         1.2-5      2023-02-24 [1] RSPM (R 4.4.0)
 fs              1.6.5      2024-10-30 [1] CRAN (R 4.4.0)
 future          1.34.0     2024-07-29 [1] CRAN (R 4.4.0)
 future.apply    1.11.3     2024-10-27 [1] CRAN (R 4.4.0)
 generics        0.1.3      2022-07-05 [2] CRAN (R 4.4.0)
 ggplot2         3.5.1      2024-04-23 [2] CRAN (R 4.4.0)
 globals         0.16.3     2024-03-08 [2] CRAN (R 4.4.0)
 glue            1.8.0      2024-09-30 [1] CRAN (R 4.4.0)
 gower           1.0.1      2022-12-22 [2] CRAN (R 4.4.0)
 gplots          3.2.0      2024-10-05 [1] CRAN (R 4.4.0)
 graph           1.84.0     2024-10-29 [1] RSPM (R 4.4.0)
 gridExtra       2.3        2017-09-09 [2] CRAN (R 4.4.0)
 gtable          0.3.6      2024-10-25 [1] CRAN (R 4.4.0)
 gtools          3.9.5      2023-11-20 [2] CRAN (R 4.4.0)
 hardhat         1.4.0      2024-06-02 [2] CRAN (R 4.4.0)
 hexbin          1.28.5     2024-11-13 [1] CRAN (R 4.4.0)
 htmltools       0.5.8.1    2024-04-04 [2] CRAN (R 4.4.0)
 htmlwidgets     1.6.4      2023-12-06 [1] RSPM (R 4.4.0)
 httpuv          1.6.15     2024-03-26 [1] RSPM (R 4.4.0)
 httr            1.4.7      2023-08-15 [2] CRAN (R 4.4.0)
 IDPmisc         1.1.21     2024-02-08 [2] CRAN (R 4.4.0)
 interp          1.1-6      2024-01-26 [2] CRAN (R 4.4.0)
 ipred           0.9-15     2024-07-18 [1] CRAN (R 4.4.0)
 iterators       1.0.14     2022-02-05 [2] CRAN (R 4.4.0)
 jpeg            0.1-10     2022-11-29 [2] CRAN (R 4.4.0)
 jsonlite        1.8.9      2024-09-20 [1] CRAN (R 4.4.0)
 knitr           1.49       2024-11-08 [1] CRAN (R 4.4.0)
 later           1.3.2      2023-12-06 [1] RSPM (R 4.4.0)
 lattice         0.22-6     2024-03-20 [2] CRAN (R 4.4.0)
 latticeExtra    0.6-30     2022-07-04 [2] CRAN (R 4.4.0)
 lava            1.8.0      2024-03-05 [2] CRAN (R 4.4.0)
 lifecycle       1.0.4      2023-11-07 [2] CRAN (R 4.4.0)
 listenv         0.9.1      2024-01-29 [2] CRAN (R 4.4.0)
 logger        * 0.4.0      2024-10-22 [1] CRAN (R 4.4.0)
 lubridate       1.9.3      2023-09-27 [2] CRAN (R 4.4.0)
 magrittr        2.0.3      2022-03-30 [2] CRAN (R 4.4.0)
 MASS            7.3-61     2024-06-13 [1] CRAN (R 4.4.0)
 Matrix          1.7-1      2024-10-18 [1] CRAN (R 4.4.0)
 matrixStats     1.4.1      2024-09-08 [1] CRAN (R 4.4.0)
 memoise         2.0.1      2021-11-26 [2] CRAN (R 4.4.0)
 mgcv            1.9-1      2023-12-21 [2] CRAN (R 4.4.0)
 mime            0.12       2021-09-28 [2] CRAN (R 4.4.0)
 miniUI          0.1.1.1    2018-05-18 [1] CRAN (R 4.4.0)
 ModelMetrics    1.2.2.2    2020-03-17 [2] CRAN (R 4.4.0)
 multcomp        1.4-26     2024-07-18 [1] CRAN (R 4.4.0)
 munsell         0.5.1      2024-04-01 [2] CRAN (R 4.4.0)
 mvtnorm         1.3-2      2024-11-04 [1] CRAN (R 4.4.0)
 nlme            3.1-166    2024-08-14 [1] CRAN (R 4.4.0)
 nnet            7.3-19     2023-05-03 [2] CRAN (R 4.4.0)
 parallelly      1.39.0     2024-11-07 [1] CRAN (R 4.4.0)
 parsedate       1.3.1      2022-10-27 [2] CRAN (R 4.4.0)
 paws          * 0.7.0      2024-09-17 [1] CRAN (R 4.4.0)
 paws.common     0.7.7      2024-10-03 [1] CRAN (R 4.4.0)
 paws.storage    0.7.0      2024-09-11 [1] CRAN (R 4.4.0)
 permute         0.9-7      2022-01-27 [2] CRAN (R 4.4.0)
 pillar          1.9.0      2023-03-22 [2] CRAN (R 4.4.0)
 pins            1.4.0      2024-10-07 [1] CRAN (R 4.4.0)
 pkgbuild        1.4.5      2024-10-28 [1] CRAN (R 4.4.0)
 pkgconfig       2.0.3      2019-09-22 [2] CRAN (R 4.4.0)
 pkgload         1.4.0      2024-06-28 [1] CRAN (R 4.4.0)
 plotrix         3.8-4      2023-11-10 [2] CRAN (R 4.4.0)
 plyr            1.8.9      2023-10-02 [2] CRAN (R 4.4.0)
 png             0.1-8      2022-11-29 [2] CRAN (R 4.4.0)
 polyclip        1.10-7     2024-07-23 [1] CRAN (R 4.4.0)
 pROC            1.18.5     2023-11-01 [2] CRAN (R 4.4.0)
 prodlim         2024.06.25 2024-06-24 [1] CRAN (R 4.4.0)
 profvis         0.4.0      2024-09-20 [1] CRAN (R 4.4.0)
 promises        1.3.0      2024-04-05 [1] RSPM (R 4.4.0)
 proxy           0.4-27     2022-06-09 [2] CRAN (R 4.4.0)
 pryr            0.1.6      2023-01-17 [2] CRAN (R 4.4.0)
 purrr           1.0.2      2023-08-10 [2] CRAN (R 4.4.0)
 R.methodsS3     1.8.2      2022-06-13 [2] CRAN (R 4.4.0)
 R.oo            1.27.0     2024-11-01 [1] CRAN (R 4.4.0)
 R.utils         2.12.3     2023-11-18 [2] CRAN (R 4.4.0)
 R6              2.5.1      2021-08-19 [2] CRAN (R 4.4.0)
 rappdirs        0.3.3      2021-01-31 [2] CRAN (R 4.4.0)
 RColorBrewer    1.1-3      2022-04-03 [2] CRAN (R 4.4.0)
 Rcpp            1.0.13-1   2024-11-02 [1] CRAN (R 4.4.0)
 recipes         1.1.0      2024-07-04 [1] CRAN (R 4.4.0)
 remotes         2.5.0      2024-03-17 [2] CRAN (R 4.4.0)
 reshape2        1.4.4      2020-04-09 [2] CRAN (R 4.4.0)
 Rgraphviz       2.50.0     2024-10-29 [1] RSPM (R 4.4.0)
 rjson           0.2.23     2024-09-16 [1] CRAN (R 4.4.0)
 rlang           1.1.4      2024-06-04 [2] CRAN (R 4.4.0)
 rmarkdown       2.29       2024-11-04 [1] CRAN (R 4.4.0)
 rpart           4.1.23     2023-12-05 [2] CRAN (R 4.4.0)
 RProtoBufLib    2.18.0     2024-10-29 [1] RSPM (R 4.4.0)
 rstudioapi      0.17.1     2024-10-22 [1] CRAN (R 4.4.0)
 S4Vectors       0.44.0     2024-10-29 [1] RSPM (R 4.4.0)
 sandwich        3.1-1      2024-09-15 [1] CRAN (R 4.4.0)
 scales          1.3.0      2023-11-28 [2] CRAN (R 4.4.0)
 sessioninfo     1.2.2      2021-12-06 [1] CRAN (R 4.4.0)
 shiny           1.9.1      2024-08-01 [1] CRAN (R 4.4.0)
 stringi         1.8.4      2024-05-06 [2] CRAN (R 4.4.0)
 stringr         1.5.1      2023-11-14 [2] CRAN (R 4.4.0)
 survival        3.7-0      2024-06-05 [1] CRAN (R 4.4.0)
 TH.data         1.1-2      2023-04-17 [2] CRAN (R 4.4.0)
 tibble          3.2.1      2023-03-20 [2] CRAN (R 4.4.0)
 tidyr           1.3.1      2024-01-24 [2] CRAN (R 4.4.0)
 tidyselect      1.2.1      2024-03-11 [2] CRAN (R 4.4.0)
 timechange      0.3.0      2024-01-18 [2] CRAN (R 4.4.0)
 timeDate        4041.110   2024-09-22 [1] CRAN (R 4.4.0)
 urlchecker      1.0.1      2021-11-30 [1] CRAN (R 4.4.0)
 usedist         0.4.0      2020-03-01 [2] CRAN (R 4.4.0)
 usethis         3.0.0      2024-07-29 [1] CRAN (R 4.4.0)
 utf8            1.2.4      2023-10-22 [2] CRAN (R 4.4.0)
 uuid            1.2-1      2024-07-29 [1] CRAN (R 4.4.0)
 vctrs           0.6.5      2023-12-01 [2] CRAN (R 4.4.0)
 vegan           2.6-8      2024-08-28 [1] CRAN (R 4.4.0)
 withr           3.0.2      2024-10-28 [1] CRAN (R 4.4.0)
 xfun            0.49       2024-10-31 [1] CRAN (R 4.4.0)
 XML             3.99-0.17  2024-06-25 [1] CRAN (R 4.4.0)
 xml2            1.3.6      2023-12-04 [2] CRAN (R 4.4.0)
 xtable          1.8-4      2019-04-21 [1] RSPM (R 4.4.0)
 yaml            2.3.10     2024-07-26 [1] CRAN (R 4.4.0)
 zlibbioc        1.52.0     2024-10-29 [1] RSPM (R 4.4.0)
 zoo             1.8-12     2023-04-13 [2] CRAN (R 4.4.0)

 [1] /home/fpkerckh/R/x86_64-pc-linux-gnu-library/4.4
 [2] /opt/R/4.4.0/lib/R/library

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

@DyfanJones
Copy link
Member

Do you know the equivalent code in python boto3? paws is closer to boto3 the aws cli.

@FMKerckhof
Copy link
Author

Sure, I tested the following boto3 equivalent, which works (Python 3.12.1 for windows, boto3 : 1.34.136)

import boto3

client = boto3.client('s3')

response = client.restore_object(
    Bucket = 'bucket_with_restore_objs',
    Key = 'key_to_restore',
    RestoreRequest={}
)

This works like a charm and initiates recovery without any problems

@DyfanJones
Copy link
Member

@FMKerckhof thanks for this.

Long shot (I don't think it will fix the issue but want to double check), can you check if the dev version is still having this issue:

install.packages('paws', repos = c(pawsr = 'https://paws-r.r-universe.dev', CRAN = 'https://cloud.r-project.org'))

@FMKerckhof
Copy link
Author

Hi @DyfanJones : I installed the dev version as instructed, restarted my session but I am seeing the same error

@DyfanJones
Copy link
Member

Hi @FMKerckhof, sadly I haven't been able to get around to this (currently working on migrating the vendor api from aws-sdk-js to botocore). However in the mean time, I noticed that empty named lists will create "{}".

jsonlite::toJSON(setNames(list(), character()))
#> {}

Created on 2024-12-13 with reprex v2.1.1

Would passing one of them fix this issue?

s3con$restore_object(
    Bucket = bucket_with_restore_objs,
    Key =   key_to_restore,
    RestoreRequest = setNames(list(), character())
)

@FMKerckhof
Copy link
Author

Hi @DyfanJones : I understand, I am already super grateful for you helping me look in the correct place - also: to me it is not really clear how paws' handlers serialize the argument of RestoreRequest in this case. I assumed jsonlite::toJSON was used, but sadly still

s3con$restore_object(Bucket = bucket_with_restore_objs,
                     Key =   key_to_restore,
                     RestoreRequest = setNames(list(),character()))

just results in the same error as above: Error: MissingRequestBodyError (HTTP 400). Request Body is empty.

Do you have some insights into paws' R code w.r.t. handlers? Is this where I should look? How does paws serialize these arguments?

I can see that the API reference actually requires an XML rather than a json for the payload (https://docs.aws.amazon.com/AmazonS3/latest/API/API_RestoreObject.html#API_RestoreObject_RequestSyntax) so somehow the R code has to create an XML payload for the POST request?

From

s3_restore_object <- function(Bucket, Key, VersionId = NULL, RestoreRequest = NULL, RequestPayer = NULL, ChecksumAlgorithm = NULL, ExpectedBucketOwner = NULL) {

I can see that a new operation and new request are made, but from the code for new request

new_request <- function(client, operation, params, data, dest = NULL) {
I don't see how the body is passed along?

Kind regards,

FM

@FMKerckhof
Copy link
Author

related? #537

@DyfanJones DyfanJones added the bug 🐞 Something isn't working label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐞 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants