Preserve content after elastic beanstalk deployment - amazon-ec2

I have a Symfony2 website running on Amazon EC2 and Elastic Beanstalk. Each time I deploy a git version of my project immediately lost the contents of a folder ("/web/uploads")
Is there a way to tell to Elastic Beanstalk that this content shouldn´t be overriden?
I was thinking on specify an extra command on container_commands parameter inside my .ebextention file but I´m not sure it is the best way to resolve the problem.

You can't preserve that content. You will need to store it externally in a location such as S3, RDS, DynamoDB, etc. The other thing about Elastic Beanstalk to note is that if it scales up another instance of your app it won't have the content you stored locally and won't have access to it. I know it sounds harsh and limiting, but having an automated config/deploy is less trouble in the long run, IMHO. ;)

Related

How to update a laravel project in aws Elastic beanstalk, while keeping the same storage

I want to update my Laravel project in aws beanstalk, but the problem is the storage in tha aws elastic beanstalk is now different , and i want to keep it, i dont know how , cuz my Project contains a storage folder, but it's empty, and if i update it , i'll loose all the files
how can i update the code, but keep the storage ?
Your application should be designed to be stateless. The reason is that your EB instances always run in an Auto Scaling group.
This means that they can be terminated and replaced at any time, without your knowledge or involvement. There are many scenarios under which that may happen. Examples are, Availability Zone re-balance, migration to new physical hardware, scaling in and out activities, or instance health degradation.
Subsequently, you are always at risk loosing your storage, whether you like it or not.
Therefore you application should be designed as stateless, which means that it does not store any data on the instance. This is achieved usually by storing the data in an external storage such as EFS:
How can I mount an Amazon EFS volume to an instance in my Elastic Beanstalk environment?
But if you still want to keep your design, you can always use .ebextentions scripts to help you replace the storage folder. Specifically, in Commands you would make a copy of your storage folder to a safe location at the start of the new deployment. Then in Container commands you would copy the files back to your new application folder, just before the new deployment completes.

How To Stop Data From Getting Deleted On AWS Code Pipeline Having a Laravel Application

I have an elastic beanstalk environment set with code pipeline to my repository which is a Laravel site.
When I push a new change to the master branch it gets changed in the ec2, AND DELETES ALL DATA IN STORAGE.
I can't find a similar question online, so any ideas on how can I fix this issue?
Elastic Beanstalk runs on instances that don't persist data between redeployments by default. You need to re-design app to use one of the available options if you really need stable local storage.
Take a look at Persistent storage section in the doc below.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/concepts.concepts.design.html

Scale Magento on AWS Elastic Beanstalk

I have looked in the Magento & AWS Documentation but that didn't really help.
I've installed Magento on Elastic Beanstalk with 1 instance, I proceeded to snapshot the volume and make an AMI and changed the AMI setting in Elastic Beanstalk. Then spun up 2 more instances in the other availability zones. They went back to the Magento installation pages.
How do I fix this? I thought the AMI made from the snapshot would of captured the DB and other files created on installation. Meaning they'd just connect the DB and run.
Cheers to anyone who helps!
You probably don't want your database installed on your EC2 inside the elastic beanstalk. Since elastic beanstalk just removes the instance when there is an error on it and spawns a new one. You then end up loosing data. Besides that you need 1 single database server, not a database server on each of the EC2 instances inside the elastic beanstalk.
You want a separate database server, I personally always use Amazon RDS for this since this is made for this purpose.
When you are getting the install page it probably means Magento cannot locate your app/etc/local.xml. Since AWS normally gets your files from git and it is best practice to not have your local.xml in version control you are probably missing this one?
Hope that I pointed you in the right direction.
Keep in mind that the database is just your first challange, next things you are going to need to handle is:
Sessions (database is a good option but I use AWS ElastiCache with
Redis)
Cache (again, AWS ElastiCache with Redis)
Media Storage (I use S3 with S3FS and CloudFront)
CDN (CloudFront)
Here are some sites that have helped me setting up my first elastic beanstalks with Magento:
http://www.aschroder.com/2013/04/actually-running-magento-on-amazons-elastic-beanstalk-cloud-platform/
http://www.slideshare.net/corleycloud/scale-your-magento-app-with-elastic-beanstalk

Why AWS Beanstalk service is using S3 bucket?

I've launched an application in AWS -> Beanstalk using pre-installed server template.
In the process of Beanstalk installation I see it is creating S3 bucket. I'm pretty sure that I didn't select any option to use S3 bucket. If S3 bucket is needed for the Beanstalk application, can you tell me how it works together and what is the purpose? Can I prevent using S3 with Beanstalk?
This S3 bucket is indeed automatically created by Elastic Beanstalk for your new application.
It is used to store some environment files, and more important, zipped builds of your app (each one being a different version). The Beanstalk deployment script simply downloads the .zip from the bucket to the EBS volume.
It looks like there is no option on AWS to change this.
By the way, why don't you want to use S3?

How do I run my application code (PHP) across my various Amazon EC2 instances?

I've been trying to get to grips with Amazons AWS services for a client. As is evidenced by the very n00bish question(s) I'm about to ask I'm having a little trouble wrapping my head round some very basic things:
a) I've played around with a few instances and managed to get LAMP working just fine, the problem I'm having is that the code I place in /var/www doesn't seem to be shared across those machines. What do I have to do to achieve this? I was thinking of a shared EBS volume and changing Apaches document root?
b) Furthermore what is the best way to upload code and assets to an EBS/S3 volume? Should I setup an instance to handle FTP to the aforementioned shared volume?
c) Finally I have a basic plan for the setup that I wanted to run by someone that actually knows what they are talking about:
DNS pointing to Load Balancer (AWS Elastic Beanstalk)
Load Balancer managing multiple AWS EC2 instances.
EC2 instances sharing code from a single EBS store.
An RDS instance to handle database queries.
Cloud Front to serve assets directly to the user.
Thanks,
Rich.
Edit: My Solution for anyone that comes across this on google.
Please note that my setup is not finished yet and the bash scripts I'm providing in this explanation are probably not very good as even though I'm very comfortable with the command line I have no experience of scripting in bash. However, it should at least show you how my setup works in theory.
All AMIs are Ubuntu Maverick i386 from Alestic.
I have two AMI Snapshots:
Master
Users
git - Very limited access runs git-shell so can't be accessed via SSH but hosts a git repository which can be pushed to or pulled from.
ubuntu - Default SSH account, used to administer server and deploy code.
Services
Simple git repository hosting via ssh.
Apache and PHP, databases are hosted on Amazon RDS
Slave
Services
Apache and PHP, databases are hosted on Amazon RDS
Right now (this will change) this is how deploy code to my servers:
Merge changes to master branch on local machine.
Stop all slave instances.
Use Git to push the master branch to the master server.
Login to ubuntu user via SSH on master server and run script which does the following:
Exports (git-archive) code from local repository to folder.
Compresses folder and uploads backup of code to S3 with timestamp attached to the file name.
Replaces code in /var/www/ with folder and gives appropriate permissions.
Removes exported folder from home directory but leaves compressed file intact with containing the latest code.
5 Start all slave instances. On startup they run a script:
Apache does not start until it's triggered.
Use scp (Secure copy) to copy latest compressed code from master to /tmp/www
Extract code and replace /var/www/ and give appropriate permissions.
Start Apache.
I would provide code examples but they are very incomplete and I need more time. I also want to get all my assets (css/js/img) being automatically being pushed to s3 so they can be distibutes to clients via CloudFront.
EBS is like a harddrive you can attach to one instance, basically a 1:1 mapping. S3 is the only shared storage stuff in AWS, otherwise you will need to setup an NFS server or similar.
What you can do is put all your php files on s3 and then sync them down to a new instance when you start it.
I would recommend bundling a custom AMI with everything you need installed (apache, php, etc) and setup a cron job to sync php files from s3 to your document root. Your workflow would be, upload files to s3, let server cron sync files.
The rest of your setup seems pretty standard.

Resources