October 6, 2018

CI/CD using AWS Developer Tools @ AWS Community Day Bengaluru 2018


I was indeed glad to join hands with Nirmala Gopal to co-present on CD/CD using AWS Developer Tools at the 2nd edition of AWS Community Day Bengaluru 2018 held at Ritz Carlton on 6th Oct 2018.Thanks to AWS User Group Bengaluru for the great community lead collaborating learning platform and I was happy to be part of the elite group to organise / host the event. 

Agenda

  • An overview of AWS CI CD Services
  • 3 use cases leveraging AWS CI CD Services
  • Template files used in CodeBuild, CodeDeploy and Serverless Application Deployment.  
  • How do you debug you build or deployment failures? 
  • And how do you rollback in case of failure
  • Details around Generic Pipeline
  • Metrics to gauge DevOps 


Well, this was not an AWS Developer Tools 101 course! But was more about how AWS developer tools can be leveraged to create a powerful and scalable developer environment that can help you to get the code changes from the source to production faster than ever.






Refer http://bit.ly/AWSCICD_Slides and a blog http://bit.ly/AWSCICDLAB on Lab Series with 3 important workflows leveraging AWS Developer Tools.

September 28, 2018

LAB 13: Create a pipeline using AWS CodePipeline for Lambda deploy

This Lab has the step by step instructions to create a CI CD pipeline for a Serverless Application Deployment - Lambda using AWS CodeCommit, AWS CodeBuild, AWS Lambda, AWS CodeDeploy & AWS CodePipeline

Ensure to complete LAB 9 through LAB 12 including pre-requisite as stated in AWS Developer Tools CI CD Lab blog.

Login to AWS Console as `codedeploy_user`, go to AWS CodePipeline and create a pipeline with the following configuration

Create a Pipeline














Add Approve & Execute Stage

Once the above pipeline is created, edit to add 2 more stages as ApproveChangeSet and ExecuteChangeSet


Select the ARN of the SNS topic you have created earlier in this Lab series

Run the Pipeline

We have 5 stages as Source, Build, Staging, ApproveChangeSet and ExecuteChangeSet.
After the Build & Staging (after creating the CloudFormation ChangeSet), the pipeline is waiting on the manual approval.

Approval process

Based on our email configured in SNS Topic: Subscription, email notification will be sent as follows and the user can launch the URL provided for Approve or Reject and approve it.




Once the Manual approval is completed, ExecuteChangeSet stage will be executed and the Lambda function is created through CloudFormation template.






September 27, 2018

LAB 12: AWS CI CD Create Service Role for CloudFormation Deploy & Lambda

In this Lab, you will be creating a Service Role to do the CloudFormation deployment and Lambda Execution 

Ensure to complete LAB 9 through LAB 11 including pre-requisite as stated in AWS CI CD - 3rd Workflow - Serverless Application Deployment Lab blog
Login to AWS Console as `codedeploy_user` & go to AWS IAM dashboard -> Roles -> Create Role, select AWS Service as the type of trusted entity and proceed with the below configuration to create the role named CloudFormationServiceRole




Create an in-line policy CFN_Lambda_CICD_Policy with the policy document from Github.

Create Lambda Service Role


Create an in-line policy policy_LambdaWorker with the policy document from Github.


LAB 11 - AWS CI CD - Setup a Build Project in AWS CodeBuild for Lambda

This Lab has the step by step instructions to create & configure a Build using AWS  CodeBuild, which will compile the latest commit of the Lambda function, generate the artifact and uploaded to the named S3 bucket.

Ensure to complete LAB 9 through LAB 10 including pre-requisite as stated in AWS CI CD - 3rd Workflow - Serverless Application Deployment Lab blog.
Please note that for the purpose of this example, the Serverless Application is using demo-4-codedeploy as the bucket name. Make sure to edit that with your S3 bucket name before you proceed further.

Login to AWS Console as `codedeploy_user` & go to AWS CodeBuild from AWS Console, click Create Project and proceed with the configuration as follows

Build Source


Build Environment


Storying Build Artifacts


Enabling Build Logs




Save the Build & Run. Verify that the artifact is uploaded to S3 Bucket.

buildspecl.yml

Here is the closer look of buildspec.yml used in this example. In addition to this, you can environment variables as stated below

<add buildspec.yml>


Debugging CodeBuild

  • AWS CodeBuild is a managed service, which uses pre-defined container images for handling builds. Hence you will not have access to the container images running your build.
  • Local Build Support is enabled for AWS CodeBuild since May 2018, which you can use for debugging issues locally.
  • Enabling Logging to CloudWatch or S3 is key to monitor the build progress from AWS Management Console and for debugging in case of failures

LAB 10: Setup Repository in AWS CodeCommit for Lambda

This Lab has the step by step instructions to setup a Repository in AWS CodeCommit, add the pre-developed Lambda Application Code and commit the Changeset
Ensure that you have already went through the AWS CI CD using AWS Developer Tools & create IAM User, Group and S3 bucket before we move forward.
  1. Login to AWS Console as `codedeploy_user` & go to AWS CodeCommit dashboard
  2. Create an empty repository as, codecommit_lambda and you may Skip SNS Topic as of now and view the Connect to your repository screen

  1. 3. Get the clone URL (say git clone https://git-codecommit.us-east-1.amazonaws.com/v1/repos/codecommit_lambda), paste run it on your terminal. It will ask for username and password, enter the Git Credentials you have generated in Lab-9. You will get a warning that you appear to have cloned an empty repository and you are good to proceed.

  2. Download the Serverless Application source code from here and commit to your Git Repo using the commands as in below command line reference
  3. $ git clone <git URL>

                $ git init
     
                $ git status
  4. $ git add .
  5.                   $ git commit -m "Adding Serverless Application to CodeCommit Repo"
                      $ git push
                      $ git status

Now your source code is in git and may use the below command to commit the changes, if any, to the source code
  • git status - To view the changes 
  • git add . - to add all changes to the local repo and use git add <folder[/file]> to add selected folder or file to the local repo
  • git rm . - to add all changes to the local repo and use git rm <folder[/file]> to add selected folder or file to the local repo
  • git commit -m “what changes are getting in”
  • git commit --amend - will open the editor for you to modify the commit. Commit can be modified from command line as well using git commit --amend -m “New Commit”
  • git push - push the changes to the remote
  • git log -2 - gives the last two commit
  • git  branch -lvv - gives the local branches with remote mapping
  • git checkout <branchname> - to checkout from a remote branch
  • git branch -D <branchname> - to delete a local branch
  • git reset --hard <branchname> - to do a hard reset to the head of the revision from the remote - This is helpful if your local branch is messed-up and you want to overwrite everything from remote.