How to create a signed S3 address

I would like to read csv files from S3 using freadfrom the package data.tableas follows:

 ulr_with_signature <- signURL(url, access_key, secret_key)
 DT <- fread(ulr_with_signature)

Is there somewhere a package or piece of code that will allow me to create a URL using an access / secret key pair.

I would not want to use awsclidata to read.

+4
source share
1 answer

You can use AWS S3 package :

To read:

# These variables should be set in your environment, but you could set them in R:
Sys.setenv("AWS_ACCESS_KEY_ID" = "mykey",
       "AWS_SECRET_ACCESS_KEY" = "mysecretkey",
       "AWS_DEFAULT_REGION" = "us-east-1")

library("aws.s3")

If you have an R object objthat you want to save in AWS, then read:

s3save(obj, bucket = "my_bucket", object = "object")
# and then later
obj <- s3load("object", bucket = "my_bucket")

, ( AWS) . s3save. RDS s3saveRDS s3readRDS.

, , 'get_object' , :

raw_data <- get_object('data.csv', 'my_bucket')

# this method to parse the data is copied from the httr library
# substitute encoding from as needed
data <- iconv(readBin(raw_data, character()), from="UTF-8", to="UTF-8")

# now the data can be read by any R function, eg.
read.csv(data)
fread(data)

# All this can be done without temporary objects:
fread(iconv(
  readBin(get_object('data.csv', 'my_bucket'), character()),
  from="UTF-8", to="UTF-8"))

" URL" , . , : .

" " , . , . .

+6

All Articles