cloudyr / aws.s3

Amazon Simple Storage Service (S3) API Client
https://cloud.r-project.org/package=aws.s3
381 stars 148 forks source link

Not Able to upload files in S3 post downloading latest packages #258

Open pranavsiddharth opened 6 years ago

pranavsiddharth commented 6 years ago

Please specify whether your issue is about: Post downloading latest packages I am not able to upload files to S3. Seems like a region issue as the S3 request URL being generated is "https://us-east-2.s3.us-east-2.amazonaws.com/a2isxsrp/Leaderboard.htm" which is incorrect. Any idea how to resolve this?

If you are reporting (1) a bug or (2) a question about code, please supply:

Put your code here:

## load package
library("aws.s3")

## code goes here
Sys.setenv("AWS_ACCESS_KEY_ID" = "ACCESS",
           "AWS_SECRET_ACCESS_KEY" = "SECRET",
           "AWS_DEFAULT_REGION" = "us-east-2")

put_object("Leaderboard.htm", bucket = "a2isxsrp",acl = c("public-read"), verbose = T, check_region = F)

##Output
Checking for credentials in user-supplied values
Checking for credentials in Environment Variables
Using Environment Variable 'AWS_ACCESS_KEY_ID' for AWS Access Key ID
Using Environment Variable 'AWS_SECRET_ACCESS_KEY' for AWS Secret Access Key
Using Environment Variable 'AWS_DEFAULT_REGION' for AWS Region ('us-east-2')
Non-AWS base URL requested.
S3 Request URL: https://us-east-2.s3.us-east-2.amazonaws.com/a2isxsrp/Leaderboard.htm
Executing request with AWS credentials
Checking for credentials in user-supplied values
Using user-supplied value for AWS Access Key ID
Using user-supplied value for AWS Secret Access Key
Using user-supplied value for AWS Region ('us-east-2')
Checking for credentials in user-supplied values
Using user-supplied value for AWS Secret Access Key
Using user-supplied value for AWS Region ('us-east-2')
Parsing AWS API response
Redirection: (301) Moved Permanently
List of 6
 $ Code     : chr "PermanentRedirect"
 $ Message  : chr "The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this"| __truncated__
 $ Bucket   : chr "us-east-2"
 $ Endpoint : chr "s3.amazonaws.com"
 $ RequestId: chr "31368267C47D0E0D"
 $ HostId   : chr "f6xw9f+ctZM6asC2BcetfgEfZryrmyDPtwG5ceDeLFZ3SnXdpaMY/ECguye2xOThDSRs8Oq9R3Q="
 - attr(*, "headers")=List of 8
  ..$ x-amz-bucket-region: chr "us-east-1"
  ..$ x-amz-request-id   : chr "31368267C47D0E0D"
  ..$ x-amz-id-2         : chr "f6xw9f+ctZM6asC2BcetfgEfZryrmyDPtwG5ceDeLFZ3SnXdpaMY/ECguye2xOThDSRs8Oq9R3Q="
  ..$ content-type       : chr "application/xml"
  ..$ transfer-encoding  : chr "chunked"
  ..$ date               : chr "Thu, 20 Sep 2018 22:09:54 GMT"
  ..$ connection         : chr "close"
  ..$ server             : chr "AmazonS3"
  ..- attr(*, "class")= chr [1:2] "insensitive" "list"
 - attr(*, "class")= chr "aws_error"
 - attr(*, "request_canonical")= chr "PUT\n/a2isxsrp/Leaderboard.htm\n\ncontent-length:15\nhost:us-east-2.s3.us-east-2.amazonaws.com\nx-amz-acl:public-read\nx-amz-da"| __truncated__
 - attr(*, "request_string_to_sign")= chr "AWS4-HMAC-SHA256\n20180920T220952Z\n20180920/us-east-2/s3/aws4_request\nb78865f4d12d9419d27a771a9a43b9e705daedc8ed9eca330ba0e74"| __truncated__
 - attr(*, "request_signature")= chr "AWS4-HMAC-SHA256 Credential=AKIAJQKDFC3UCDREDYFQ/20180920/us-east-2/s3/aws4_request, SignedHeaders=content-length;host;x-amz-ac"| __truncated__
NULL
Error in parse_aws_s3_response(r, Sig, verbose = verbose) : 
  Moved Permanently (HTTP 301).

## session info for your system
sessionInfo()

R version 3.3.1 (2016-06-21) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C LC_TIME=English_United States.1252

attached base packages: character(0)

other attached packages: [1] aws.s3_0.3.20

loaded via a namespace (and not attached): [1] httr_1.3.1 magrittr_1.5 R6_2.2.2 assertthat_0.2.0 graphics_3.3.1 tools_3.3.1
[7] base64enc_0.1-3 huxtable_4.1.0 utils_3.3.1 curl_3.2 grDevices_3.3.1 Rcpp_0.12.16
[13] aws.signature_0.4.1 crayon_1.3.4 stats_3.3.1 datasets_3.3.1 xml2_1.2.0 stringi_1.1.7
[19] methods_3.3.1 stringr_1.3.1 digest_0.6.14 base_3.3.1

RyanKlaas commented 6 years ago

would recommend not putting your access tokens on the internet; however, the answer is in the response object ..$ x-amz-bucket-region: chr "us-east-1"

switch "AWS_DEFAULT_REGION" = "us-east-2" to be "us-east-1" and it should work