检查EC2实例上AmazonS3到R上是否存在文件?
我试图通过AmazonEC2实例上的Rstudio检查s3上是否存在文件。基本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" = "
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")