AWS Lambda:任务超时 [英] AWS Lambda: Task timed out

查看:612
本文介绍了AWS Lambda:任务超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们被要求为我的学校项目编写一个在AWS Lambda中运行的Java代码.应该获取特定URL的源代码,然后将其上传到S3存储桶. Java代码应在AWS Lambda上运行.

We have been asked for my school project to write a Java code that runs in AWS Lambda. It is supposed to get the source code of the specific URLs and then upload it to an S3 bucket. The Java code should be running on AWS Lambda.

我将源代码获取到Java中的String变量.然后,我有一个while循环,尝试将字符串写入/tmp目录中的文件.然后将文件上传到S3.

I get the source code to the String variable in Java. Then I have while loop that tries to write the String into a file in /tmp directory. Then the file is uploaded to S3.

一切正常,但我只能使用一个特定的URL.我已经跟踪到了这个问题:

Everything works but I get stuck with one specific URL. I have tracked the problem to this point:

try {
    BufferedWriter out = new BufferedWriter(new FileWriter("/tmp/url.txt"));
    out.write(source_code);  //Replace with the string 
    //you are trying to write  
    out.close();
}
catch (IOException e) {
    System.out.println("Exception ");
}

最奇怪的是,当我在本地测试代码时,一切正常.在我的计算机上的/tmp目录中创建文件,然后将其上传到S3存储桶.但是,当我在Lambda中运行代码时,出现以下错误:

The weirdest thing is, when I test the code locally, everything works. File is created in /tmp directory on my computer and then it is uploaded to an S3 bucket. However, when I run the code in Lambda, I get the following error:

Task timed out after 15.00 seconds

您知道为什么Lambda在这种情况下无法将文件写入其temp目录,并且可以与其他文件一起使用吗?

Any idea why Lambda fails to write the file into its temp directory in this specific case and it works with others?

推荐答案

Amazon Lambda旨在用作响应事件的事件驱动系统.流程是:

Amazon Lambda is designed to be used as an event-driven system that responds to events. The flow is:

  • 发生什么事情会触发Lambda(例如,上传到Amazon S3,数据进入Amazon Kinesis流,直接调用Lambda函数的应用程序)
  • 创建了Lambda函数,传递了触发事件中的数据
  • Lambda函数运行
  • Something happens somewhere that triggers Lambda (eg an upload to Amazon S3, data coming into an Amazon Kinesis stream, an application invoking the Lambda function directly)
  • The Lambda function is created, data from the trigger event is passed
  • The Lambda function runs

Lambda函数的最大执行时间限制为15分钟(最近从原来的5分钟超时增加了该时间).实际限制是在创建Lambda函数时配置的.之所以有此限制,是因为Lambda函数本应小而又快,而不是大型应用程序.

Lambda functions are limited to a maximum execution time of 15 minutes (this was recently increased from the original 5 minutes timeout). The actual limit is configured when the Lambda function is created. The limit is in place because Lambda functions are meant to be small and quick rather than being large applications.

您的错误消息显示为Task timed out after 15.00 seconds.这意味着,AWS 在任务达到15秒的运行时间后有意停止了该任务.它与当时的功能无关,也与正在处理的文件无关.

Your error message says Task timed out after 15.00 seconds. This means that AWS intentionally stopped the task once it hit a run-time of 15 seconds. It has nothing to do with what the function was doing at the time, nor the file that was being processed.

要解决的问题::在Lambda函数的配置页面上增加超时设置.

To fix: Increase the timeout setting on the configuration page of your Lambda function.

这篇关于AWS Lambda:任务超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆