Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing local filesystem in AWS lambda

Tags:

aws-lambda

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

like image 263
SquareRoot Avatar asked Feb 26 '16 01:02

SquareRoot


People also ask

Does Lambda have local storage?

Since customers could not cache larger data locally in the Lambda execution environment, every function invoke had to read data in parallel, which made scaling out harder for customers. Today, we are announcing that AWS Lambda now allows you to configure ephemeral storage ( /tmp ) between 512 MB and 10,240 MB.

Does AWS Lambda have filesystem?

I am very happy to announce that AWS Lambda functions can now mount an Amazon Elastic File System (Amazon EFS), a scalable and elastic NFS file system storing data within and across multiple availability zones (AZ) for high availability and durability.

Can we mount EFS to Lambda?

An EFS is a file system that you can mount from different instances, including a Lambda function. One major caveat is that all these resources should be in the same security group and VPC (Virtual Private Cloud).


2 Answers

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.

like image 200
Cheeko Avatar answered Sep 24 '22 09:09

Cheeko


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.

like image 42
Enrique G Avatar answered Sep 24 '22 09:09

Enrique G