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.
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.
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 ");
}
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
Any idea why Lambda fails to write the file into its temp directory in this specific case and it works with others?