Balaji Vajjala's Blog

A DevOps Blog from Trenches

1.1 Setup and Checkin Application Code

Learning Objectives

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

  • Setup your environments.

  • Setup and Checkin Application Code

    • Learning Objectives
    • Check in changes to application code
    • Create an AWS account
    • Create a New Key Pair
    • Launch an AWS Utility instance using CloudFormation
    • Apply a bucket policy using CloudFormation
    • Create an S3 bucket to host credentials
    • Create SQS queues
    • Setup your GitHub Account
    • Checkin application code to GitHub
  • Launch a CloudFormation stack.

  • Make an application code change and commit it to GitHub.

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

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.
1
$ chmod 400 ditc.pem
  1. 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.
1
$ ssh -i ditc.pem ec2-user@ec2-23-20-4-122.compute-1.amazonaws.com         
  1. 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.
1
$ ssh-keygen -t rsa -C "paul.duvall@stelligent.com"       
  1. Display the contents of the public key and copy the contents to your clipboard.
1
$ cat ~/.ssh/id_rsa.pub
  1. 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.
  2. Go back to the AWS CLI instance, go to the root directory and type the following from the command line. Replace bvajjala with your GitHub userid.
1
$ git clone git@github.com:bvajjala/sample_app.git              
  1. Go back to the AWS CLI instance, go to the root directory and type the following from the command line. Replace bvajjala with your GitHub userid.
1
$ git clone git@github.com:bvajjala/devopsinthecloud.git       
  1. Type ls from the command prompt. You should see sample_app and devopsinthecloud as subdirectories.
  2. 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. Open the home.html.erb file
1
$ sudo vim home.html.erb       
  1. Make a modification to the contents of the file and save it.
  2. Change directory to sample_app.
  3. Add the file in Git
1
$ git add .
  1. Commit the file to Git
1
$ git commit -m "Modify the application code" 
  1. Push it to the Git master.
1
$ git push

SPECIAL: Synchronize your GitHub fork with latest bvajjala/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 bvajjala with your GitHub username.
  2. Change the directory
1
$ cd ditcsync
  1. Get the latest from the bvajjala repo.
  2. Fetches any new changes from the original repo
1
$ git pull upstream master
  1. Push changes to your forked repo.
1
$ git push