paws-r / paws

Paws, a package for Amazon Web Services in R
https://www.paws-r-sdk.com
Other
305 stars 37 forks source link

Getting 403 error when trying to access public S3 bucket #790

Closed matthewt-assurity closed 2 weeks ago

matthewt-assurity commented 2 weeks ago

Hello!

I'm trying to access a public S3 bucket, however I'm getting a 403 error.

Code I'm running:

s3 <- paws::s3()

bucket_name = "herbariumnsw-pds"

s3$list_objects_v2(
  Bucket = bucket_name,
  MaxKeys = 2
)

Exact response message:

Error: InvalidAccessKeyId (HTTP 403). The AWS Access Key Id you provided does not exist in our records.

The error makes it sound like I am trying to provide an access key ID, which I'm not explicitly, but I wonder if it is picking up on what is in my local AWS keys saved via running aws configure with the AWS CLI. Either way, I shouldn't need an access key to access a public S3 bucket, so I'm a bit confused.

For reference, I'm following this tutorial https://blog.djnavarro.net/posts/2022-03-17_using-aws-s3-in-r/. \

I am using paws instead of cloudyr, but I don't think this should make a difference as to whether I can access a public S3 bucket or not (I hope!).

DyfanJones commented 2 weeks ago

Hi sorry to hear that, have you tried to setting anonymous? https://www.paws-r-sdk.com/docs/set_service_parameter/ I am currently having a holiday hence my slow replies.

matthewt-assurity commented 2 weeks ago

Thanks @DyfanJones, I've updated my code to the below and it works!

s3 <- paws::s3(
  config = list(
    credentials = list(
      anonymous = TRUE
    )
  )
)

bucket_name = "herbariumnsw-pds"

objects <- s3$list_objects_v2(
  Bucket = bucket_name,
  MaxKeys = 2
)

I got a little stuck when I was using anonymous initially. I first tried to set this in the wrong function, i.e

objects <- s3$list_objects_v2(
  config = list(
    credentials = list(
      anonymous = TRUE
    )
  ),
  Bucket = bucket_name,
  MaxKeys = 2
)
DyfanJones commented 2 weeks ago

@matthewt-assurity I'm glad you got it working. I will close this ticket. Feel free open again if the issue persists