Setting up a test environment for my EC2 and RDS setup - mysql

I have an API which runs on an EC2 instance and connects to a MySQL db.
My goal is to set up a clone of this which I can use as a development platform. Currently everything I do is live.
Ideally I would have up to date data in the test verison of the MySQL database, so maybe a script to auto clone the live version to the test version every day would suffice?
I have a standalone .exe application which calls the API.
What is the typical development work flow here?
I guess I will need a seperate folder on my server for my dev branch. Then I can call the dev url from my standalone application.
So during testing I would change the API url from "/live-api/login.php" to "/test-api/login.php" in my standalone program. I would have the /live-api folder and the /test-api folder hooked up to to the same repo, where the /test-api is always on the dev branch and /live-api is always on master branch?
Thanks!

Your architecture looks good.. You have two folder [ if u are on tomcat two webapps] which come from different branches.
Regarding test db getting updated with production db; it looks tricky. Do you want to have independent RDS for your test environment ? One option is that at night anyway you would have configured to take a snapshot [backup] of your production db.. You can re-create your test RDS db with this new snapshot.. Only drawback would be that any test data created on your test environment will get lost daily..

Related

I need a foolproof checklist for hosting an already built e-commerce site on Amazon Web Services

I have built an e-commerce website on my local computer that uses Django version 2.2 and python 3.7.
The website consists of:
fancyfetish is the main project directory.
The apps, (cart, users, baseapp, products, blog) are all stored in their own directory 'apps.
Within the settings folder I have three settings files:
- production.py
- base.py
- development.py
The static file in the main directory is where I put collectstatic files.
Media is where I store externally uploaded images (product images for example)
Docs is just random bits like a hand drawn site layout.
Static files like JS and CSS are stored within baseapp, within apps.
I want to host this website on Amazon Web Services, and I assume I need to use Elastic Beanstalk. I went through the process of trying to host with free version of EB, installed the EB CLI, and after using eb create and eb deploy on the CLI my website appeared.
However, the static files didn't load properly in the first instance because I had not properly configured DJANGO_SETTINGS_MODULE. I have now done this. But before deploying I added eb migrate functionality so that I could also migrate my database.
This seems to have messed everything up. I can no longer deploy because there is a DATABASE error, which I expected. The error said 'Not able to connect to MySQL database through 'localhost'. Well, of course it cant.
So, in order to deploy my site on AWS I needed to configure the databases, because with the eb migrate functionality it will no longer deploy without trying to also connect to my database using the settings I have configured.
I have so far, whilst in development mode, connected my project to MySQL and everything is running perfectly on localhost, with my models transferring beautifully to the database just as I would like.
I worked out that I need to create a database on AWS, obviously. So I set up an RDS. I didn't link it to my deployed application because it would appear that the application doesn't have an environment that I can see when I log into my console. So where my project has been deploying to I don't know, because it doesn't look like the CLI version is connected to the online version in my console.
So I thought I'd deal with that problem later and work out how to make a database, which I managed to do. However, migrating the database I already have up and running on MySQL to my RDS database seems impossible, and there are not very good instructions. Let alone trying to then connect said database to my deployed application, which doesn't seem to sync with my local app.
So, I have ended up deleting everything because I was becoming so confused, with so many new directories (.ebextensions etc etc) and a database that wont connect, a project that won't deploy, a database that wont point to my project etc. I ended up created an EC2 folder and all sorts, getting myself massively confused with what I actually need to do to make this whole thing work.
If any part of this ramble makes any sense to anyone out there, and you yourself have managed to deploy a larger django project to AWS and keep your existing databases then please do let me know. But I have a feeling this may be a long shot.
Basically I need a step by step list of what to do to deploy:
For example:
1) Create an elastic beanstalk instance
2) Create an environment on CLI that syncs to the one in my AWS console
etc
etc
(With how to's if you possibly have the time!)
Thank you, and I am so sorry for being so confused by something that may be simple
Edited to show my process:
I have built a directory called .ebextensions with a file within it called django.config with the following content:
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: fancyfetish/wsgi.py
I have run the following command:
eb init -p python-3.6 fancyfetish
There was no output as a result of this in the terminal, however a directory was created called .elasticbeanstalk with one file in it called config.yml
I then typed eb init to create an SSH key pair and there was no output from this command at all:
As you can see I have tried doing this several times.
Instead I created a key pair manually within AWS console and a file automatically to my computer called keyname.pem
I then typed into the console
chmon 400 path/to/key/keyname.pem
This provided no output on the terminal so I cannot know if it worked.
I moved the downloaded SSH file into the .SSH directory in the Home directory of my computer, and then in the terminal typed:
eb init -k nameofkey
The output was:
WARNING: Uploaded SSH public key for "fancyfet" into EC2 for region us-
west-2.
I then went on to type
eb create fancyfet-env
And an environment was created with the following output:
I know that this has to do with databases and connecting to MySQL.
I then typed:
eb deploy
With the following output:
So now comes the bit where I get stuck, successfully creating a database that connects to my already existing database that is populated with database in MySQL, and connecting the project to the database.
HELP!(Thank you so much!)

How to migrate a Project from 'OpenShift Web Console' to '(Next Gen) Web Console'?

Is there a way to migrate a server application (with its repository), to the new Next Gen Console?
I have already a WildFly server in my personal account at URL: https://openshift.redhat.com/app/console/applications
But when I open the Next Gen Console, it's empty, and suggest me to create new project with a new server.
https://console.preview.openshift.com/console/
Is there a way to avoid setting up everything again?
I would like to keep server configurations, git repository, and Jenkins app from my former OpenShift Web Console.
Sorry, there is no direct migration tool. The manner in which the systems works is quite different from an operational standpoint, but you are also potentially going to have to tweak how your application code is organised and configured. I would suggest you create a fresh application in the new version to learn more how they are different and then you can plan what you may need to do to migrate it. I would suggest making using of the Google Group for OpenShift if you have more questions as it provides a better forum for discussion.
https://groups.google.com/forum/#!forum/openshift

Duplicating existing cakephp app for development

I need to make a development version of a cakePHP app with its own db so that a developer can work on it without disturbing the current users.
I thought it would be simple, I just copied the entire director /project to /project_dev and then copied the DB "project_db" to "project_db_dev". Then I went into /project_dev/config/database.php and changed the db to "project_db_dev".
When I went to see what I had done, I saw the app was still connecting to the same db, as if I'd changed nothing. I realized that the original folder name was referenced in /app/webroot/.htaccess so do I need to find/replace all instances of that folder name?
What steps should I follow to duplicate an existing cakePHP app?
You need to setup some kind of development lifecycle.
Generally speaking the developer shouldn't be doing any development on the server. The best way to handle it is locally using a stack of some kind such as Lamp (Linux, Apache, Mysql, PHP) switch out linux with other OS's. There are multiple cloud solution to these environments to such as Koding.com
Using something like Git for version control the developer can develop locally then push the code through to the server after is being thoroughly tested locally or on a dev server or some kind.
Keeping Dev work and Live work away from each other is key.
Could do with a bit more information.
If both databases are hosted on the same server and you have permission to access them both with the same user then all you have to do is change the name of the database in your database.php
If not you will also have to update the IP and any other additional settings port etc.
If you are still having troubles email me simpsond1988#gmail.com

Switching where my domain points to for safe production deploys

Say I have one prod environment and one dev environment in elastic beanstalk. I deploy my code to dev and it works and all's well, but when I deploy to production I get an error (note this is possible since sometimes instances get corrupted during deploys and apache breaks). What are the pros and cons of this solution:
have 2 prod environments that you toggle between on every deploy
deploy to the one not being used
if the deploy works, point yourdomain.com to the new production and if not, your old production is safe
Now, is SEO a concern -- if I switch around my domain between two elastic beanstalk environments, would the SEO be harmed?
The following solution is one that I have used many times without incident but remember to always test you solutions before production use.
The solution will use the following environment names which you should map to internal DNS names:
PROD01.elasticbeanstalk.com > www.example.com
PROD02.elasticbeanstalk.com
DEV01.elasticbeanstalk.com > dev-www.example.com
Typically, after developing and testing your application locally, you will deploy your application to AWS Elastic Beanstalk environment DEV01. At this point, your application will be live at URL dev-www.example.com.
Now that you have tested your application, it is easy to edit your application, redeploy, and see the results.
When you are satisfied your changes you made to your application, you can deploy it to your PROD02.elasticbeanstalk.com production environment. Using the Application Versions page promote the code running on DEV01 onto PROD02. Using your hosts file make sure everything is in order and then hit the URL swap.
This will switch PROD01.elasticbeanstalk.com and PROD02.elasticbeanstalk.com environment URL's seamlessly with zero downtime on your application.
Once you've made sure all your traffic is switched you can then update your original production environment following the same method, switch back and remove PROD01.elasticbeanstalk.com to prevent the extra cost (or you can leave it if you don't mind the $$ spend).

Development environment Sinatra & MySQL in 2 computers

I'm developing a Sinatra and MySQL application. I'm using as development environment a Macbook Air and an iMac. The server runs on a FreeBSD VPS running unicorn behind nginx.
I'd like to somehow automate the whole procedure, I develop in both iMac and MBA. Depends on time I have free in the office (MBA) or time I spend writing code at home (iMac). I have setup MySQL on both macs.
I manually dump and restore the database in order to be able to test my application locally before making any change to the server.
I'd like to automate the process of: Syncing the MySQL database if possible, keep the code up-to-date to all locations without using cloud storage if possible.
Best Regards,
I think there are many ways to solve this problem.
So this is just on idea how to achieve this.
Create a git repo on your server and write a small shell script which sync your db from somewhere. This script can you trigger by a git hook http://git-scm.com/book/en/Customizing-Git-Git-Hooks#Client-Side-Hooks
For your syncing script you may have a look at this -> https://github.com/xssnark/mysql-db-sync or I'm sure you find something.