1.1 Setup and Checkin Application Code

Learning Objectives

By the end of this lesson you will be able to:

Check in changes to application code

Slide1

Create an AWS account

Create an AWS account by registering for CloudFormation.

  1. Go to the AWS CloudFormation service: http://aws.amazon.com/cloudformation/.
  2. Click the Sign Up Now button
  3. If you don’t have any account with AWS, choose I’m a New User; Otherwise, select enter your credentials.
  4. Enter your login information, contact and billing information and read/accept AWS terms. During the account creation process, you will need to enter a code into your phone for verification purposes.
  5. Once you've completed the registration process, you will be sent an email. Click on http://aws.amazon.com/account/.

Create a New Key Pair

  1. Go to the list of key pairs by going to this link.
  2. Select the Create Key Pair button and enter ditc in the Key Pair Name field and the Create button. Save the file onto your computer for future use. Click the Close button.

Launch an AWS Utility instance using CloudFormation

  1. Click this link to launch an AWS command-line interface instance. This template is provided courtesy of AWS Training.
  2. Click Continue.
  3. In the KeyName field, enter the key pair (i.e. ditc) that you created in the previous section. Select the checkbox next to I acknowledge that this template may create IAM resources and click Continue.
  4. Click Continue again, then Close.
  5. Once the status in CloudFormation is CREATE_COMPLETE, select the checkbox next to AWSCLI.
  6. Select the Outputs tab in the bottom panel and copy the DNS name for the instance into your clipboard
  7. Find the ditc.pem file on your computer. If you are are a *nix-based computer, you will need to modify the permissions to 400.
    $ chmod 400 ditc.pem
    			
  8. From the directory where your ditc.pem is located, enter the command below to SSH into the utility instance. In the example below, the DNS name is ec2-23-20-4-122.compute-1.amazonaws.com. Yours will be different.
    $ ssh -i ditc.pem ec2-user@ec2-23-20-4-122.compute-1.amazonaws.com
    				
  9. Enter yes to the security prompt.

Apply a bucket policy using CloudFormation

  1. Create a new S3 bucket. This will be used to host your build artifacts. Call it something like ditcxyzartifacts where xyz are your initials. I'm calling my bucket stelligentlabs throughout this LiveLesson.
  2. Click this link to run the bucket policy change.
  3. Click Continue.
  4. Enter the name of the bucket you you just created (e.g. "ditcxyzartifacts") and click Continue.
  5. Click Continue again, then Close.
  6. Once the status in CloudFormation is CREATE_COMPLETE, the policy has been applied to your S3 bucket.

Create an S3 bucket to host credentials

  1. Create a new S3 bucket and call it ditcxyzcreds - where xyz are your initials. Write down both of these S3 buckets (ditcxyzcreds and ditcxyzartifacts) as you will use them several times throughout this LiveLesson.

Create SQS queues

  1. Go to the SQS tab and create two new queues. One called CloudFormationStacks and the other called Deployment. Set the Default Visibility Timeout to 0.

Setup your GitHub Account

  1. If you don't have a Github, create a free one here: https://github.com/signup/.
  2. Login to your account by going to https://github.com/login
  3. Go to https://github.com/stelligent/devopsinthecloud
  4. Click the Fork button. A message will display "Where do you want to fork this to?". Click on the button that says Fork to YOURUSERID.
  5. Go to https://github.com/stelligent/sample_app
  6. Click the Fork button. A message will display "Where do you want to fork this to?". Click on the button that says Fork to YOURUSERID.
  7. Create an SSH keypair by SSH'ing to the AWSCLI instance you created by launching the CloudFormation stack in the section above. In the example below, I'm using the email address that's registered with my GitHub account. You can find yours by going to https://github.com/settings/profile/. Accept the defaults after running this command.
    $ ssh-keygen -t rsa -C "paul.duvall@stelligent.com"
    			
  8. Display the contents of the public key and copy the contents to your clipboard.
    $ cat ~/.ssh/id_rsa.pub
    			
  9. After logging into your GitHub account, go to your GitHub SSH Keys settings at https://github.com/settings/ssh/. Click on the Add SSH Key button, give it a name and paste the contents of the public key into the Key text field. Then, click the Add key button. Enter your GitHub password when prompted.
  10. Go back to the AWS CLI instance, go to the root directory and type the following from the command line. Replace PaulDuvall with your GitHub userid.
    $ git clone git@github.com:PaulDuvall/sample_app.git
    			
  11. Go back to the AWS CLI instance, go to the root directory and type the following from the command line. Replace PaulDuvall with your GitHub userid.
    $ git clone git@github.com:PaulDuvall/devopsinthecloud.git
    			
  12. Type ls from the command prompt. You should see sample_app and devopsinthecloud as subdirectories.
  13. You can also setup the same environment on your local computer. This way it's easier to use the IDE of your choice.

Checkin application code to GitHub

  1. From the root directory of your EC2 instance change directory to sample_app.
  2. $ cd /home/ec2-user/sample_app/app/views/pages
    				
  3. Open the home.html.erb file
    $ sudo vim home.html.erb
    			
  4. Make a modification to the contents of the file and save it.
  5. Change directory to sample_app.
  6. $ cd /home/ec2-user/sample_app
    				
  7. Add the file in Git
    $ git add .
    			
  8. Commit the file to Git
    $ git commit -m "Modify the application code"
    			
  9. Push it to the Git master.
    $ git push
    			  

SPECIAL: Synchronize your GitHub fork with latest stelligent/devopsinthecloud repository

By default, GitHub will not update changes from the https://github.com/stelligent/devopsinthecloud GitHub repository. Since I will be making changes and updates after the video publication, you will want to go through the following steps to merge the changes we make at stelligent/devopsinthecloud with your forked repository.
  1. Clone your repository. Replace PaulDuvall with your GitHub username.
  2. $ git clone git@github.com:PaulDuvall/devopsinthecloud.git ditcsync
    				
  3. Change the directory
    $ cd ditcsync
    			
  4. Get the latest from the stelligent repo.
  5. $ git remote add upstream https://github.com/stelligent/devopsinthecloud.git
    				
  6. Fetches any new changes from the original repo
    $ git pull upstream master
    			
  7. Push changes to your forked repo.
    $ git push