How can automatic deploy yii2 app when Elastic Beanstalk instance is terminated and created a new instance - amazon-web-services

Currently I have setup my yii2 website on AWS Elastic beanstalk. I followed following steps :
Created Elastic Beanstalk app and environment : Platform PHP 7.0, RDS database
Created SSH connection from EC2 instance of elastic beanstalk using putty with .pem file
In Apache folder I have cloned my yii2 git repo using (sudo git clone repo_url) command
Installed composer using this link https://gist.github.com/asugai/6694502
Run command : (sudo composer install) in my repo folder
Edited common/config/main-local.php and made db connection
And run migration using (sudo php yii migrate)
Setup a domain for this elastic beanstalk app
Now I don't know how should I proceed further and I am facing following problems :
Elastic Balance loader is creating new instance and terminating current one when it fails or health goes in severe.
Due this, my all data in that instance is lost. To make it work I am doing all steps again and again manually.
How can I make my domain https (SSL certified)
How can make easy process to pull new changes from git
I already have a working site in nodeJS. which is using elastic beanstalk, elastic balance loader, RDS(postgres), S3 bucket, cloudfront for Route 53, SSL certificate (https), code pipeline, code commit. And AWSCLI at local to deploy nodeJS app.
my question is about I want to use same flow for yii2 advance app.
Can anyone please help me here?
Thanks in advance :)

Related

Docker container runs local, but not on AWS Elastic BeanStalk

I created Docker container with flash and gunicorn. I tested it locally successfully and pushed it without any problems to Docker hub. I also have AWS EB CLI installed so I tested it with eb local run. Everything worked fine.
I used the following link to deploy it on AWS Elastic BeanStalk. When I visit URL of the application, I am getting HTTP ERROR 504. I looked at log file and there are any error messages.
How can I further troubleshoot this issue?

How to connect to existing elastic beanstalk instance locally from cli?

I am very much new to aws. I have created an environment in elastic beanstalk and deployed my application there using zipped code. The application is up and running now. Now i want to stop and start my elastic beanstalk instance from cli in windows. I could not find any stop button in the aws elastic beanstalk console.
I have installed awsebcli using below command:
pip install awsebcli
Now, i want to connect to my existing environment in elastic beanstalk and stop or start the environment at my will.
How can i do that?
The way the EBCLI (awsebcli) works is that you associate an empty directory on your computer with an EB application.
go to an empty directory
eb init --region <region name>. When prompted for the application name, choose the application you created previously.
eb terminate <environment name>. This will terminate the environment.
To create a new environment, perform eb create.

Where are the node.js app files installed in an AWS elastic beanstalk instance?

In an AWS elasticbeanstalk instance, where are the node.js app files deployed to? I wanted to ssh to the machine and debug some issues and wanted to check that the files were deployed correctly. I checked /var/ but didn't see an app directory there.
It's in the /tmp/deployment/application folder during deployment and then it is moved to /var/app/current.
The node logs are in /var/log/nodejs/nodejs.log

How to connect to specific instance behind Elastic Load Balancer

I'm deploying my app via Elastic Beanstalk, which creates and Elastic load balancer and puts all my instances behind it (3 or more).
Is there a way to contact each of these instances directly? I want to trigger a specific command on each instances (git pull command to synchronize with the latest code in my remote repo).
I have the list of IP address and public DNS of the instances from PHP SDK but since the firewalls rules restricts the source of IP address to the elastic load balancer IP on port 80, I can't seem to access them directly.
Is there a way around it?
P.S. The SSH port seems to open for all traffic, but how can I create a trigger with that? I'm hoping to create a PHP script to automate this with a webhook on the remote repo.
I highly suggest you use the EB CLI with git integration for all deployments, no matter how small. It is great because you can map a git branch to an environment with eb use YOUR_ENV then when you run eb deploy with that branch checked out it will deploy to that environment.
There is a lot of work involved in ensuring multiple servers pull the correct code and everything is working as expected. What if a server is in the processes of spinning up but is not ready for SSH so your script skips it and it does not get the new code?
Also, what happens when a new server spins up but it is using the old application because that's what is in EB? You could have your kickstart do a git pull but then what happens when you are not ready to push, a new server starts and is alone with the new code?
I could probably find 5 more edge cases without breaking a sweat. Look into eb deploy, you will be happy you did.
You need to setup a CI (or make a simple web service) and create a webhook in your repository. Your CI need to get all instances under your Elastic Beanstalk environment and then call git pull via SSH.
Or, just create a cron job in your all instances via .ebxensions script.
I thought it's not a good practice in Elastic Beanstalk to run git pull in order to synchronize your app with your git repo. Because, it misused the Application Version semantic meaning. Sometimes, you can't determine which app version are in your instances from Application Version. It's better to create a new Application Version in Elastic Beanstalk to deploy a new app version.
If you host your repo in Github, you can take a look into CodeDeploy.

manage migrations when deploy rails app with AWS Elastic Beanstalk

AWS Elastic Beanstalk is easy to use for deploying rails app on Amazon EC2. By set RAILS_SKIP_MIGRATIONS as true, eb won't run the migrations itself so I can manage migrations myself.
However,SSH to the EC2 instance that created by Beanstalk, I can't find the deployed rails app in the home directory.Then I don't know where to manually rake the migrations.
I wonder why the rails app can't be found on the EC2 instance since the instance is the web server to host the app. Is it hidden somewhere? And how should I manually rake the migrations?
Thanks
Try take a look at /var/app/current.
I think you can't find rake, because elastic beanstalk run ruby environment in virtual environment - rvm. Try to find in the directory /opt environment variables which set up ruby environment for current terminal. I'm not sure for ruby, but for python you should do: source /opt/python/current/env.