我们已经要求我的学校项目编写一个在AWS Lambda中运行的Java代码.它应该获取特定URL的源代码,然后将其上载到S3存储桶.Java代码应该在AWS Lambda上运行.
我在Java中获取String变量的源代码.然后我有while循环尝试将String写入/ tmp目录中的文件.然后将文件上传到S3.
一切正常,但我遇到了一个特定的URL.我已经跟踪了这个问题:
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 ");
}
Run Code Online (Sandbox Code Playgroud)
最奇怪的是,当我在本地测试代码时,一切正常.文件在我的计算机上的/ tmp目录中创建,然后上传到S3存储桶.但是,当我在Lambda中运行代码时,我收到以下错误:
Task timed out after 15.00 seconds
Run Code Online (Sandbox Code Playgroud)
知道为什么Lambda在这个特定情况下无法将文件写入临时目录并且与其他人一起使用?