Search code examples
amazon-web-servicesaws-lambda

Can I make Lambda's /tmp folder accessible from external?


I have a Lambda function, which takes very short videos (100-200KB) as input and packages the video using Dash/Hls, and respond to the request with a Manifest file. The media player will then based on the Manifest file to access the video.

For my particular use, the packaged video is only for one time use, after it is accessed, I no longer need to keep it. Therefore, I want to explore the feasibility to put the packaged video in the /tmp folder of the Lambda function instead of S3.

That said, I face the following issues:

  1. Is the /tmp folder accessible from outside? I tried to visit the /tmp folder directly from browser, which returns a "Missing Authentication Token" error. Not sure if I can get a token somewhere.
  2. Although AWS says the /tmp folder is ephemeral and is isolated for each instance, occasionally, I get an error saying "xxx.mp4 already exist, do you want to overwrite it?", indicating the /tmp folder is not empty and is shared with other instances.

So, I am not sure if this is even feasible. If not, is there any other way to make it work? For such small files and one time use, using S3 is kind of waste and also increases delay.


Solution

  • AWS Lambda functions run in containers. The containers are not accessible from outside the Lambda function. It is not possible to send requests to a running Lambda container, so it cannot act as a web server.

    Lambda containers can be reused by subsequent executions, which is why you saw previous files in the /tmp/ directory. It is a good idea to delete temporary files before exiting the function to avoid consuming all of the temporary storage.

    You might enjoy reading this series of articles about how AWS Lambda operates: Operating Lambda: Performance optimization – Part 1 | AWS Compute Blog