I am trying to read/write to S3 from R in an EC2 using write_using() from the aws.s3 package.
What I've done so far
The EC2 has an IAM attached that allows read/write to a specific AWS S3 bucket
I have associated the IAM with the EC2. I have also created a bucket (in this example please assume it is called my-unique-bucket)
When I go into the EC2 and open R, then run something like s3write_using(mtcars, FUN = write.csv, object = "mtcars.csv", bucket = "my-unique-bucket")
I see
List of 4
$ Code : chr "AccessDenied"
$ Message : chr "Access Denied"
$ RequestId: chr "3B942C125C154B49"
$ HostId : chr "0dgc4Iuv3EXdQxMgkh4Qkxt+aADzxsVYp6pq2k3/OjSztFlV1nftjn4MkIvNZ+wCVqzeJsttY44="
- attr(*, "headers")=List of 6
..$ x-amz-request-id : chr "3B942C125C154B49"
..$ x-amz-id-2 : chr "0dgc4Iuv3EXdQxMgkh4Qkxt+aADzxsVYp6pq2k3/OjSztFlV1nftjn4MkIvNZ+wCVqzeJsttY44="
..$ content-type : chr "application/xml"
..$ transfer-encoding: chr "chunked"
..$ date : chr "Tue, 18 Jun 2019 12:57:45 GMT"
..$ server : chr "AmazonS3"
..- attr(*, "class")= chr [1:2] "insensitive" "list"
- attr(*, "class")= chr "aws_error"
NULL
Error in parse_aws_s3_response(r, Sig, verbose = verbose) :
Forbidden (HTTP 403).
I would have expected this to work? Instead, it looks like an authentication issue
Next?
I am not sure what to try next, as I was hoping the above would work.
Given it doesn't, do I need to somehow authenticate the EC2 (or R session running on the EC2)? I would think that authentication using root credentials defeats the purpose of the IAM (since the root user has permissions for everything, whereas the IAM associated with the instance has just read/write to S3 permissions). So I am not sure that's the right thing to do (it seems there would be a better way - i.e. a way that let's S3 know the EC2 has an IAM allowing it access). But I am not sure how to do this or where I have gone wrong in attempting this