Search code examples
.netlinuxamazon-web-servicesamazon-elastic-beanstalk

Does AWS Elastic Beanstalk clear the tmp folder?


I have a .net 6 web API deployed on AWS Elastic Beanstalk. In that app I have a functionality to store images temporarily in the tmp folder and then upload them with a background job later. I am using Path.GetTempPath(); for that matter.

But occasionally I get errors logged, that file "/tmp/xyz.png" could not be found. Does AWS clear the tmp folder? Or maybe it is switching the instance? I couldn't find any resources regarding that "issue". Is there a better alternative to store those temporary files to ensure they aren't removed? Maybe "under var/app/current" but I don't know if AWS would remove files from there when changing the instance as well. To be honest I don't know why AWS is creating new instances at all, maybe there is an option to forbid that? Often my instances look like that: enter image description here

(Not having deployed a new version or anything, even when I'm connected to the instance via ssh it just stops responding and when I reload my instances it looks like that and I have to connect to the new instance)


Solution

  • I would advise to always build stateless instances on AWS ElasticBeanstalk. Depending on your configuration, ElasticBeanstalk can add or remove instances several times per day. So it's better to use an external service for saving files, like AWS S3 or AWS ElasticFilesystem. So your files are not lost when instances are removed. And you can share files between you different instances.

    A common way to deploy a php app on ElasticBeanstalk is to mount an EFS partition to solve this problem without any code modifications. AWS doc