Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检查EC2实例上AmazonS3到R上是否存在文件?_R_Amazon Web Services_Amazon S3 - Fatal编程技术网

检查EC2实例上AmazonS3到R上是否存在文件?

检查EC2实例上AmazonS3到R上是否存在文件?,r,amazon-web-services,amazon-s3,R,Amazon Web Services,Amazon S3,我试图通过AmazonEC2实例上的Rstudio检查s3上是否存在文件。基本R的exists()函数和file.exists()函数为每个文件返回FALSE。下面是我的代码,存在。类型存在于s3中,而不存在。类型不存在 library("aws.s3") Sys.setenv("AWS_ACCESS_KEY_ID" = "key1", "AWS_SECRET_ACCESS_KEY" = "key2", "AWS_DEFAULT_REGION" = "

我试图通过AmazonEC2实例上的Rstudio检查s3上是否存在文件。基本R的
exists()
函数和
file.exists()
函数为每个文件返回
FALSE
。下面是我的代码,
存在。类型
存在于s3中,而
不存在。类型
不存在

library("aws.s3")
Sys.setenv("AWS_ACCESS_KEY_ID" = "key1",
           "AWS_SECRET_ACCESS_KEY" = "key2",
           "AWS_DEFAULT_REGION" = "key3"
)

existing_file_path = "s3://bucket_name/folder_name/exists.type"
not_existing_file_path = "s3://bucket_name/folder_name/not_exists.type"

exists(existing_file_path) #returns FALSE
exists(not_existing_file_path) #returns FALSE

file.exists(existing_file_path) returns FALSE
file.exists(not_existing_file_path) returns FALSE

aws.s3::get_object(existing_file_path) #reads the entire file
aws.s3::get_object(not_existing_file_path) #gives error

我尝试了
list.files
另外,它返回
字符(0)

您应该使用函数
head\u object()
,该函数只返回有关对象的元数据,而不返回对象本身

aws.s3::head_object("your_file", bucket = "your_bucket")