Accessing a *.Rdata file from S3 in R given that S3 location is given

94 views Asked by At

I have a input.Rdata file in a s3 bucket at a location say:

"s3://bucket1/rcode/data/input.Rdata"

There are multiple buckets and files in each folder, not just this one file.

Question:

  1. How to load this data from s3 in R given that I have the S3 location?
  2. How to save a .Rdata in s3 in R given that I have the S3 location?

I know that there is a library called "aws.s3". But I am new to R so not sure how to use it.

Also Please note that I would like to deploy the code in AWS lambda. So the code should be compatible with it.

Could Someone please help? Thanks in advance.

1

There are 1 answers

0
Dyfan Jones On

Try out the paws package. It basically is an AWS SDK for R.

To download files from AWS S3 you can check out the documentation: https://www.paws-r-sdk.com/docs/s3_download_file/

As long as you have your credentials set up (check out: https://www.paws-r-sdk.com/developer_guide/credentials/ or https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html). This example should should work.

install.packages("paws")
client <- paws::s3()

client$download_file(
    Bucket = "bucket1",
    Key = "rcode/data/input.Rdata",
    Filename = "input.Rdata"
)

Note: if you are on linux try out the pre-built binaries for faster installation: https://www.paws-r-sdk.com/