首页 > 解决方案 > 无法从 R 在 S3 存储桶中写入 csv 文件

问题描述

我正在尝试使用以下代码将 csv 文件写入 Amazon S3 存储桶

s3write_using(gene_read_counts, FUN = write.csv, object = "gene_read_counts_test.csv", bucket = "test-bioinformatics-dev-bkt/research/bioinformatics/colo_final/data/processed/colorectal", row.names=FALSE)

我收到以下错误

文件大小为 71619789。考虑设置“multipart = TRUE”。parse_aws_s3_response(r, Sig, verbose = verbose) 中的错误:禁止 (HTTP 403)。

标签: ramazon-web-servicesamazon-s3

解决方案


在查看错误时,可能有两个方面。

  1. 似乎错误建议在上传大文件时使用 AWS-S3 分段上传。分段上传提供更快、更灵活的上传到 Amazon S3。它可以通过

    • 将对象/文件分成小块。
    • CreateMultipartUpload 使用S3 API上传初始化。
    • 使用分段上传上传部分对象。使用UploadPartCopyS3 API 的操作
    • 完成分段上传。使用CompleteMultipartUploadS3 API 的操作。
    • 同时必须执行AbortMultipartUpload如果任何部分上传失败。使用AbortMultipartUpload,任何先前上传的部分所占用的存储空间都将被释放。

    请参阅以下 AWS 文档。 https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateMultipartUpload.html https://docs.aws.amazon.com/AmazonS3/latest/API/API_UploadPart.html https://docs.aws。 amazon.com/AmazonS3/latest/API/API_CompleteMultipartUpload.html https://docs.aws.amazon.com/AmazonS3/latest/API/API_AbortMultipartUpload.html

  2. Forbidden (HTTP 403) 错误提示权限被拒绝。在这种情况下,如果用户有权访问 S3 对象,请检查 IAM 角色。

由于您使用“R”语言在 S3 中编写文件。我建议使用Put_Object函数并multipart = TRUE在函数中设置部分上传文件。

你可以使用下面的代码

   put_object(filename, object, bucketname, multipart = TRUE, acl = c("private",
     "public-read", "public-read-write", "aws-exec-read", "authenticated-read",
     "bucket-owner-read", "bucket-owner-full-control"), headers = list(), ...)

当您 multipart = TRUE在上述函数中说时,它将创建所提供对象的部分或块并在 S3 中部分上传。


推荐阅读