Accessing local filesystem in AWS lambda

31,736

Solution 1

It is possible. I have python function that does something like

  localFilename = '/tmp/{}'.format(os.path.basename(key))
  s3.download_file(Bucket=bucket, Key=key, Filename=localFilename)
  inFile = open(localFilename, "r")

Be sure you are using it for temporary storage and not to maintain any state. Depends on what you are trying to do.

Solution 2

From AWS Lambda Execution Context:

Each execution context provides 512 MB of additional disk space in the /tmp directory. The directory content remains when the execution context is frozen, providing transient cache that can be used for multiple invocations. You can add extra code to check if the cache has the data that you stored. For information on deployment limits, see AWS Lambda Limits.

Share:
31,736
SquareRoot
Author by

SquareRoot

Updated on May 21, 2020

Comments

  • SquareRoot
    SquareRoot almost 4 years

    Is it possible to access local filesystem in a AWS lambda function? If so, is there any downside to doing so?

  • SquareRoot
    SquareRoot about 8 years
    Yes. I was going to use it as intermediate storage similar to your example. Was not sure what kind of access rights we would have. Won't users be able to copy malicious code into a shared AWS resource like this?
  • Mark B
    Mark B about 8 years
    @SquareRoot the local file system your function has access to is isolated to that function. Later invocations of your function may get access to the same files, but no other Lambda function in your account or any other account will be able to access those files.
  • kilokahn
    kilokahn about 6 years
    Hi, Can anyone tell me the max amount of temp storage I get when using the /tmp folder in Lambda?
  • Janaka Bandara
    Janaka Bandara about 6 years
    @kilokahn as per aws.amazon.com/lambda/faqs you get 500MB scratch space in `/tmp/.