I am new to AWS Lambda and running a tensorflow model in AWS Lambda. Now tensorflow 1.0.0 is the one that fits into the 50Mb limit but since tensorflow 2.0 is much bigger in size it does not fit. Does anyone knows of a way to use tensorflow 2.0 with AWS lambda?
-
1Why would you want to use Tensorflow with AWS Lambda? Seems like that is not the way to go – Blokje5 Jan 15 '20 at 09:17
-
1I am using tensorflow with AWS lambda as AWS Lambda is very cheap. – Debangshu Paul Jan 15 '20 at 13:58
-
Yeah, but you are training a machine learning model (I assume at least). Lambda has a 15 minute runtime max. Machine learning can take hours even days to train (depending on your data size). If you want to do machine learning, Lambdas really are not the way to go. I would look into AWS SageMaker – Blokje5 Jan 15 '20 at 14:00
-
4I am not training I am doing the predictions. – Debangshu Paul Jan 15 '20 at 14:39
-
@DebangshuPaul have you found a solution on this issue? – Mpizos Dimitris Nov 23 '20 at 09:20
-
why not try creating a TensorFlow aws layer ? – cerofrais Jun 15 '22 at 04:11
5 Answers
AWS Lambda comes with an ephemeral storage unit in /tmp. However, please note that the ephemeral storage unit still has a storage of 512MB. You can load your dependencies to this storage, and write code accordingly.

- 2,083
- 1
- 13
- 27
-
Yes but that storage is not permanent right, I already tried downloading from s3 to the /tmp folder and it seems everytime I have to do it which is very inefficient in terms of cost and performance. is there any other way to do this? – Debangshu Paul Jan 15 '20 at 14:01
-
One of the variant is using EFS.
Run EC2 instance, mount EFS and install Tensorflow or any other library on it.
Then in lambda function you can select file system with installed libraries and import them in your function.
You can use AWS official documentation or try those tutorials.
For me it helps and i was able to import tensorflow in my lambda function.
How to use EFS (Elastic File System) with AWS Lambda: https://youtu.be/4cquiuAQBco
How to mount EFS on EC2 instance: https://youtu.be/PHVthx8lG4g
How to install library on EFS & import in lambda: https://youtu.be/FA153BGOV_A

- 399
- 7
- 19
As of March 2021
, the best solution is probably to use a container image for the Lambda as explained here.

- 6,845
- 8
- 34
- 52
I've been able to use Tensorflow
on Lambda
by deploying the function with a Docker image
. See this post

- 1,058
- 12
- 22