无法使用R访问S3上的文件

问题描述 投票:0回答:1
access_key<-"**************"
secret_key<-"****************"

bucket<- "temp"
filename<-"test.csv"


Sys.setenv("AWS_ACCESS_KEY_ID" = access_key,
       "AWS_SECRET_ACCESS_KEY" = secret_key )

buckets<-(bucketlist())
getbucket(bucket)


usercsvobj <-get_object(bucket = "","s3://part112017rscriptanddata/test.csv")
csvcharobj <- rawToChar(usercsvobj)
con <- textConnection(csvcharobj)
data <- read.csv(con)

我能够看到存储桶的内容,但无法将csv作为数据帧读取。

[1] "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Error>
<Code>PermanentRedirect</Code><Message>The bucket you are attempting to 
access must be addressed using the specified endpoint. Please send all 
future requests to this endpoint.</Message><Bucket>test.csv</Bucket>
<Endpoint>test.csv.s3.amazonaws.com</Endpoint>
<RequestId>76E9C6B03AC12D8D</RequestId>
 <HostId>9Cnfif4T23sJVHJyNkx8xKgWa6/+
  Uo0IvCAZ9RkWqneMiC1IMqVXCvYabTqmjbDl0Ol9tj1MMhw=</HostId></Error>"

我正在使用aws.S3包的cran版本。

r amazon-s3
1个回答
0
投票

我能够使用以下方法从本地r和通过r stuio服务器读取S3存储桶:data <-read.csv(textConnection(getURL(“https://s3-eu-west-1.amazonaws.com/'yourbucket'/'yourFileName”)),sep =“,”,header = TRUE)

© www.soinside.com 2019 - 2024. All rights reserved.