简体   繁体   English

AWS Lambda 上传到 S3 超时

[英]AWS Lambda upload to S3 time out

I'm fairly new to AWS Lambda and I'm facing a problem.我对 AWS Lambda 还很陌生,我遇到了一个问题。 I'm developing in Node and I'm downloading JSON file (quite big ones 12-25MB) from my S3, doing some processing and trying to upload the result in form of JSON back to S3.我正在 Node 中开发,我正在从我的 S3 下载 JSON 文件(相当大的 12-25MB),进行一些处理并尝试将结果以 JSON 的形式上传回 S3。

I was following this tutorial: https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html which does essentially the same thing.我正在关注本教程: https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html基本上做同样的事情。

My problem is that my lambda always times out when calling JSON.stringify on an object that I get as a result of my data processing and thus the file never gets uploaded back to S3.我的问题是我的 lambda 在 object 上调用JSON.stringify时总是超时,这是我的数据处理的结果,因此文件永远不会上传回 S3。 The result of my processing is also a quite big object but still smaller as the input (cca. 10MB).我处理的结果也是一个相当大的 object 但作为输入仍然更小(cca. 10MB)。
I already tried to use fast-json-stringify library but I ended up with the same result.我已经尝试使用fast-json-stringify库,但最终得到了相同的结果。

Does anyone know if there is any other faster way to convert an object to string, buffer or stream?有谁知道是否有任何其他更快的方法可以将 object 转换为字符串、缓冲区或 stream?

UPDATE更新

Here is my code:这是我的代码:

async.waterfall(
  [
    (next) => {
      s3.getObject({
        Bucket: bucketName,
        Key: keyDownload
      }, next);
    },
    (response, next) => {
      next(null, processData(JSON.parse(response.Body)));
    },
    (data, next) => {
      s3.putObject({
        Bucket: bucketName,
        Key: keyUpload,
        Body: JSON.stringify(data)
      }, next);
    }
  ], 
  (err) => {
    if (err) {
      callback(err);
    } else {
      callback();
    }
  }
);

Did you try S3 multi-part upload, I would suggest that's a place to look into -您是否尝试过 S3 分段上传,我建议这是一个值得研究的地方 -

https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html https://docs.aws.amazon.com/AmazonS3/latest/dev/mpuoverview.html

  • Just a random thought after looking at the example you are following.查看您所遵循的示例后,只是一个随机的想法。

  • if you are using the aws cli to create the lambda function just wondering what is the --timeout value that you have given.如果您使用 aws cli 创建 lambda function 只是想知道您给出的--timeout值是多少。 The example says --timeout 10 which is 10 sec which is definitely small time span.该示例说--timeout 10是 10 秒,这绝对是一个很小的时间跨度。

  • You can check/change it on the aws console as well and try and increase it to say 10 min ie 600 sec (this is just for testing if this is the problem or not later on you can get down to some appropriate value after evaluation).您也可以在 aws 控制台上检查/更改它,并尝试将其增加到 10 分钟,即 600 秒(这只是为了测试这是否是问题所在,或者稍后您可以在评估后降低到某个合适的值) .

  • The timeout is optional value while creating via aws cli.通过 aws cli 创建时,超时是可选值。 Thus the default is 3 seconds.因此默认值为 3 秒。 The maximum allowed value is 900 seconds ie 15 min.最大允许值为 900 秒,即 15 分钟。

  • Definitely multi-part upload will be helpful.绝对多部分上传会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM