G.Mounika
G.Mounika

Reputation: 425

How to get the updated 'uploads' folder from AWS Elastic BeanStalk?

I hosted my server side coding in elastic beanstalk. I used multer to upload files in 'upload' folder, that means using api the client is able to store images or pdfs etc in this 'upload' folder dynamically. When I hosted the .zip in ebs say some 3 files are stored in uploads folder. And more files are added after hosting. Now if I change my code and deploy my code to ebs, the empty uploads folder is getting created. If I download the previous code, I'm getting only the 3 files which are there at the time of hosting. I'm unable to get back the files added after the code is hosted. How to overcome this?

Upvotes: 1

Views: 927

Answers (1)

Abhyudit Jain
Abhyudit Jain

Reputation: 3748

First rule of hosting an app on ElasticBeanstalk is that your code should be stateless. By stateless, I mean it should not depend on the machine at all as instances get created and shut down depending on scaling requirements.

What I do is do everything you say, upload it to uploads folder but then I store it in S3 (or somewhere where it's safe if instance is terminated). So basically the uploads folder is just a temporary location.

The content which is dynamically created should not be a part of your codebase.

You can't get the data that is lost as whenever you deploy a new version the directory where your code is deployed is erased and new version is copied there. I believe its /var/app/current/.

Whenever you want to deal with uploads in the future, you should follow:

  1. Upload it to a temp directory on instance,
  2. Upload it to somewhere where it's safe (maybe something like AWS S3),
  3. Save the link to the object in safe storage (S3 link) into the Database so you can get the uploads if you want.

Upvotes: 1

Related Questions