尝试将文件从 lambda tmp 文件夹上传到 s3 存储桶

饼干765

我是 lambda 函数的新手,我正在尝试从 lambda 函数将文件上传到 s3 存储桶。创建多个 zip 文件到 tmp 文件夹,然后我想将该 zip 文件上传到 s3 存储桶,我已授予访问 s3 存储桶到 lambda 函数的权限,但未显示任何错误我尝试了不同的方法来解决此问题但无法修复它.


import fs from 'fs';
import AWS from 'aws-sdk';
import delay from "delay";
const s3 = new AWS.S3({
    accessKeyId: "***",
    secretAccessKey: "***",
    region: "***"
});


const uploadFullfile = () =>{
// reg ex to match
var re = /\.zip$/;

// ensure that this file is in the directory of the files you want to run the cronjob on
fs.readdir("/tmp/",function(err: any, files: any) {
    if (err) {
        console.log( "Could not list the directory.", err);
        process.exit( 1 )
    }

    var matches = files.filter( function(text: any) { return re.test(text) } )
    var numFiles = matches.length;
    if ( numFiles ) {
        // Read in the file, convert it to base64, store to S3

        for(let i = 0; i < numFiles; i++ ) {
            uploadCandidate(matches[i])
        }

    }

})


const uploadCandidate = (fileName:any) => {
  fs.readFile('/tmp/'+fileName, async(err:any, data:any) => {
     console.log("entry",fileName);
     if (err) throw err;
     
     console.log("params")
    await s3.putObject({
         Bucket: 'testbucket', // pass your bucket name
         Key: fileName, // file will be saved as testBucket/contacts.csv
         ContentType: 'application/zip',
         Body: data,
      },function (resp) {
        console.log('Done');
      });
  //delay(1000);
  //fs.unlink('/tmp/'+fileName, function(){
  //    console.log("deleting file");
  //  console.log('/tmp/'+fileName);
  //});
 
    
});
}
 
}

export default uploadFullfile;


我没有收到任何错误,并且我已授予访问我收到的 s3 存储桶输出的权限

2021-01-14T17:22:38.354+05:30   2021-01-14T11:52:38.354Z *** INFO entry state_fullfile_2021-01-14-11:01:03_part0.zip

2021-01-14T17:22:38.354+05:30   2021-01-14T11:52:38.354Z *** INFO params

2021-01-14T17:22:38.375+05:30   2021-01-14T11:52:38.374Z *** INFO entry association_fullfile_2021-01-14-11:01:03_part5.zip

2021-01-14T17:22:38.375+05:30   2021-01-14T11:52:38.375Z *** INFO params

2021-01-14T17:22:38.378+05:30   2021-01-14T11:52:38.378Z *** INFO entry remark_table_fullfile_2021-01-14-11:01:03_part1.zip

2021-01-14T17:22:38.378+05:30   2021-01-14T11:52:38.378Z **** INFO params

2021-01-14T17:22:38.394+05:30   END RequestId: ****

2021-01-14T17:22:38.394+05:30   REPORT RequestId: *** Duration: 83.91 ms Billed Duration: 84 ms Memory Size: 1024 MB Max Memory Used: 322 MB
饼干765

出现此问题是由于 VPC 端点的权限问题。这是解决方案

new-vpc-endpoint-for-amazon-s3

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

亚马逊s3,将文件上传到存储桶中的文件夹中

使用Boto3将文件上传到带前缀的S3存储桶

将图像从S3存储桶下载到Lambda临时文件夹(Node.js)

如何将文件夹上传到Azure存储

使用laravel上传到s3存储桶文件夹

Lambda Python boto3将文件存储在S3存储桶中

将Lambda部署到s3存储桶文件夹?

文件未上传到s3存储桶

Amazon S3存储桶策略,用于特定文件夹上的引用条件

将屏幕快照从AWS lambda上传到s3存储桶失败

Python-无法将文件上传到AWS S3存储桶中的已定义文件夹

使用Api Gateway(Lambda函数)将图像上传到S3存储桶

Boto3在将文件上传到S3存储桶时遇到问题

如何授予Lambda将文件上传到terraform中的s3存储桶的权限?

如何配置“ Terraform”以将zip文件上传到“ s3”存储桶,然后将其部署到lambda

使用Java AWS SDK将文件夹上传到S3存储桶

从Lambda的/ tmp文件夹中读取csv文件,对其进行过滤并将其上传到s3

如何使用lambda函数和boto3从s3存储桶读取csv文件?

将JSON文件上传到Python中s3存储桶中的特定文件夹

将文件上传到S3存储桶

您尝试访问的存储桶必须使用指定的终结点进行寻址将文件上传到AWS S3

尝试在其中保存matplotlib饼图时将空文件上传到S3存储桶

AWS Lambda:如何在S3存储桶中读取CSV文件,然后将其上传到另一个S3存储桶?

尝试直接将文件上传到Amazon S3存储桶时请求失败

如何使用 Node.js 从 AWS Lambda 中的 /tmp 文件夹将 WAV 文件上传到 S3

将文件上传到 s3 存储桶、sdk php 中的特定文件夹

无法写入 S3 存储桶上的可写文件夹 /tmp/

压缩 s3 存储桶中的对象,然后将 zip 文件夹上传到存储桶

無法在 lambda 的 /tmp/ 中看到我從 S3 存儲桶下載的文件