Drupal climbs the AWS Elastic Beanstalk
Drupal hosting on AWS Elastic Beanstalk
By Swen Mock
This article is intended to be a very basic step-by-step tutorial on how to set up Drupal within AWS Elastic Beanstalk, an Amazon Web Platform as a service (PaaS) solution. The article does not go into detail about long-term experiences of hosting or working with AWS Elastic Beanstalk and Drupal, maybe a future article will cover this interesting subject.
You will need an Amazon AWS Account to proceed with this tutorial, the account registration process should be self-explanatory enough, just follow the instructions.
I am a fan of bullet points and don't like running text in a tutorial, so, let's jump straight in:
STEP 1: Prepare your local workstation
- This step may differ depending on what local OS you have running, in my case it is OS X (10.6.8) so I will describe all necessary steps for this system. Don’t worry: you will find help easily in the official Amazon documentation
- Back to the road: Get and unzip the Elastic Beanstalk Command Line Tools, short ‘eb’ (you will need them anyway for the deployment process later on)
- Copy the unzipped files (folder) to a location of your choosing
- Add the eb location to your consoles path variable, e.g. by adding
export PATH=$PATH:<path to eb>
to your .bash_profile - At this point: Be sure you have the correct Python version installed already (2.7+ is required), I had to update mine (Note: Don't try Python 3.3+ on an Mac OS 10.6, it won't work, take Python 2.7 and everything is fine)
- You can check your Python version by typing:
python --version
STEP 1.1: Prepare Drupal to be deployed
- You will need GIT installed on your machine, if you don't have it yet, get it here!
- Get a current copy of Drupal from Drupal.org and unzip the files into a folder like ‘htdocs’
- Go to your new drupal folder, in my case this is ‘htdocs’, and initiate a git repository with the command:
git init
- Next add all the drupal files to that repository by typing:
git add . -A
- Now make a initial commit:
git commit -m “Initial Commit”
- You should now have a master branch which is currently checked out
STEP 1.2: Initialize Elastic Beanstalk CLI & configure Beanstalk environment
- I summarized these steps, for details take a look at the official Documentation
- Within your local drupal folder - in my case ‘htdocs’ - use the command:
eb init
- You will be prompted to enter your AWS Access Key ID (NOTE: ‘Key ID’ and ‘Key’ are two different things). If you need to know how to get that, check 'Getting AWS security credentials'
- Next you will be asked to enter your AWS Secret Access Key .
- Then you will be asked to select your AWS Elastic Beanstalk service region, in my case this is ‘EU West (Ireland)’
- After selecting the region you can name your application, default will be the name of your folder; in my case the folder default name was ‘htdocs’ so I entered ‘drupal’ as a new, more fitting, application name
- Next you will be asked for the environment name of your application, default is ‘[name of application]-env’; I accepted ‘drupal-env’ for my test case
- As the next step you have to choose a fitting solution stack, that means which OS the target (hosting) machine has to run; I selected ‘64bit Amazon Linux running PHP 5.4’
- After that you have to select which environment type should be used, load-balanced or single-instance; because this is a test case for me, I selected ‘single-instance’
- Next accept to create a RDS DB Instance; of course we need a database to run our Drupal application
- When you are asked whether an existing snapshot should be used or not, decline
- Now you have to enter a DB master password and retype it to confirm
- Next you can decide to make a DB snapshot
- You are asked which environment profile should be used; I used default
- After this last step, the eb config file ‘aws_credential_file’ will be written
STEP 2: Deploying Drupal as a sample application
- In your local application folder - in my case ‘htdocs’ - where you initialized eb, type:
eb start
- The upload and boot-up process of your application and the configured beanstalk environment starts, this may take several minutes - around 12 minutes in my case - perhaps you should go and get a fresh cup of coffee
- After the process has finished, your Elastic Beanstalk environment, in my case named ‘drupal-env’, should be up and healthy without problems
- Go to the Elastic Beanstalk web interface, select the register with your new environment, you will be automatically linked to the dashboard of this environment, click there the link to your environment (red marked on image):
- You will get to the drupal standard installation screen, hosted by AWS and embedded into a AWS Elastic Beanstalk environment
STEP 3: Installing Drupal
- Go through the installation steps until you are asked for database configuration
- Use ‘ebdb’ as database name and ‘ebroot’ as database username; these names were set by the eb command line interface when initialising the eb environment locally
Excursion
- If you ever want to or have to know e.g. what name your RDS database has, go to your RDS Webinterface and select 'Instances' from the menu on the left. There you get a table with available database instances:
- There you can click on the
icon to see the detailed configuration screen of that database instance:
Back to your Drupal install process:
- Unfold the ‘Advanced Options’ container to enter Host and Port of your new RDS Database instance
- You get this information at the Elastic Beanstalk web interface of your environment under the ‘Configuration’ menu item, search for ‘Data Layer’ and the box named simply ‘RDS’:
- Copy host (endpoint) url but beware to only copy the URL string, EXCLUSIVE the port ‘:3306’ suffix and paste that into your drupal installation screen
- Enter the port number, generally this will be 3306
- Press the ‘Save and Continue’ button
- Follow the next steps, configure your ‘user 1’ account and . . .
- Tada! You got Drupal within an AWS Elastic Beanstalk environment!
To finish this up, I wan't to show you how easily local changes could be deployed:
STEP 4: Deploy local changes
- Make your changes to your local files
- Add them as usual to Git, by typing
git add . -A
- Commit the added stuff
git commit -m “Update Test”
- And then, push it right to your Beanstalk environment by typing:
git aws.push
- That’s all, if everything is all right, you will see something similar to:
- Your Beanstalk Environment will be updated and restarted automatically, this may take a few seconds
- That’s all! Update complete.
As I said, this is a very basic howto get drupal into AWS Elastic Beanstalk but I hope this will be helpful to some of you.
Next time I will try to get AWS OpsWorks working with Drupal.