Quantcast
Channel: Technical Blog for Software Enthusiasts
Viewing all articles
Browse latest Browse all 26

Final Part - Customizing AWS Elastic Beanstalk

$
0
0
Finally we have reached the end of this saga of customizing AWS Elastic Beanstalk using suite of Linux Bash scripts. This post contains a link to a downloadable zip file which contains all the scripts and here are the step by step instructions on using it.

1. Download the zip file and unzip its contents into a folder, for example, "beanstalk". You should find two entries in the folder. First one is the file index.html which simply contains the basic html to display "Hello World!!! AWS Elastic Beanstalk application". The second is the directory ".ebextensions" which contains all the scripts, configuration and other essential files.

2. Open the file ".elastic-beanstalk-app" in the folder "copy-to-slash/root". You can leave the application name as "myApp" for the current testing. In case you want to change, then you will have to also change the application name in the file elastic-beanstalk.config in the "scripts/main directory". I recommend that you just make note of the three main entries and leave them unaltered. You need to provide valid values only when you actually start using our scripts to operate on beanstalk environments.

You could provide the name of the Amazon S3 bucket you want to use and also provide the deployment directory. The deployment directory should contain a secrets directory with secrets.zip file in it. The zip file is supposed to contain additional security credentials and other confidential information. If the zip file is present then its contents are unzipped to the "/" directory overwriting any existing files. Please refer to our post Security Credentials Setup for more information.

The deployment directory should also contain the directory "war" and it should have only one file with ".war" extension. This becomes necessary only when you start using the scripts to create a new environment, terminate an environment or to deploy the application to an existing environment. Please refer to our posts Creating a Staging Environment and Deploying Application to Existing Environment for detailed explanation.

3. In the same file ".elastic-beanstalk-app", you should edit the entry ROUTE53_ZONE_NAME and set it to the domain name of your choice. Please refer to our article Updating Route53 DNS Records for additional information. Route53 entries are important as the scripts depend on them for termination of an environment or to deploy application to an existing environment. If you choose to use Route53, then go to Route53 console and create a zone with the same name you specified in the file ".elastic-beanstalk-app". I strongly recommend that you to do it. For now you can edit the file directly. But at hudku.com, we make a copy of the file ".elastic-beanstalk-app", edit all the entries with the required values and make this file as part of the secrets.zip file and have it in the secrets directory of the Amazon S3 bucket.

4. You should make a war file by changing to the directory where you unzipped the zip file and by using the command "jar cvf myApp.war *", you should create myApp.war file.

5. Go to the AWS Elastic Beanstalk console and create a Sample Application using a Tomcat7 container. Even if you are interested in creating a PHP, Python or Ruby application, you could follow these steps to get yourself familiarized. Later you could launch an environment with the container of your choice.

If you have not created any Beanstalk application then you would be presented with a startup screen and I recommend that you choose the last option "Customize" and click the "Start" button. If you already have some Beanstalk environments running, then please choose "Create New Application" from the Amazon's console. The idea is to just create an environment running the Tomcat7 Sample Application provided by Beanstalk. You can refer to Amazon's documentation available here.

While creating the sample application following are the important points that require attention.

  • For the Container type, please select "64 bit Amazon Linux running Tomcat7" for now.
  • Enter myApp for the application name.
  • You should choose "Use the Sample Application" and do not try to upload the war file at this step.
  • Enter env-20130312-1400 for the Environment name as the value is not important, but the format is. This is extremely important as our scripts check the format of the environment name. The environment URL could be anything and you could provide any value of your choice.
  • Please enter the name of a valid key pair, otherwise you will not be able to SSH to the EC2 instance. You can create a key pair using EC2 console.

That's it. Just create the Tomcat7 sample application and wait for the environment to turn Green and become Ready.

6. If you want you could test the sample application by clicking on the URL displayed in the console. But continuing with our task at hand, please click on "Environment Details" and then click on "Edit Configuration". Then in the "Server" tab ensure that the value for "Existing Key Pair" is valid. Then click on the last tab "Container", go to the section "Environment Properties" and fill in the valid values for AWS_ACCESS_KEY_ID, AWS_SECRET_KEY. Without this our scripts do not work and hence this step is extremely important. Click on "Apply Changes" and wait for the changes to be applied until the environment becomes ready once again.

7. Now we are ready to deploy our ".war" file created in the step 4 above. Click on "Upload New Version", provide some name for the version, click on "Choose File" button and upload the ".war" file. Then select the option "Deploy to an existing environment after upload", ensure that the environment name displayed is correct and click on "Upload and Deploy New Version" button. If the upload is successful and the environment becomes Green again then you have successfully deployed the application along with our scripts. If you are using Route53, then you could go to Route53 console and find the entries made by our scripts.

8. Then SSH into EC2 instance and go to directory "/myApp", if you have not changed the application name in the step 1 above. In that directory you should see all our files and in the tmp directory you should see some entries. The one that is of at most importance is the directory "app-setup-log". That directory should contain two files. The first file contains entries up to the creation of a system swap file and after that the system would have rebooted. The second file then contains all the log entries for the commands executed after reboot. From then on if the same environment is reused then there would be only one log file for every deployment. You might see some errors related to crontab which can be ignored. Later you can correct the entry in the file crontab.txt or delete the entry if you do not need it.

That's it folks. Please take your time going through the scripts which we believe contains professional grade customization code. If you have already been using AWS Elastic Beanstalk and running a serious application, then we strongly feel that you would be able to appreciate the utility of the scripts we have provided and you would never want to operate the Beanstalk environments without them.

We have submitted the zip file to Amazon Sample Code & Libraries and shall definitely update this post if it gets accepted.

We request you to click on the social buttons below this blog post, if you appreciate our efforts. It would immensely warm our hearts and definitely would go a long way in encouraging us to take the time and effort to tirelessly keep coming up with useful blog posts. Appeal is ours, the decision is yours.

Here is the zip file customizing-aws-elastic-beanstalk.zip for you to download. We have successfully tested the zip file and whatever corrections we had to make to overcome some minor errors we encountered, I have updated our previous blog posts also to reflect those changes.  The contents of the zip file are as below.


Just want to mention that hudku.com is an independent entity and is in no way connected to Amazon or AWS. We on our own felt like sharing the knowledge we have acquired since we started using AWS. We sincerely believe that the information we have provided along with the bash scripts for customization could be of great value and save some serious time in trying to get going with AWS Elastic Beanstalk.

The effort was quite involved in trying to write and publish the serial of blog posts but was equally enjoyable. In the future posts we shall try to keep bringing you interesting stuff on various different topics such as C, C++, C#, Java, Database, Javascript, JQuery, Web related, etc.

You could always expect valuable, interesting and useful information in our posts as we take your time very seriously and we do not disrespect our time also.



Viewing all articles
Browse latest Browse all 26

Latest Images

Trending Articles





Latest Images