CodeCommit CodeDeploy and CodePipeline in AWS

  1. Create a CodeCommit repository in CodeCommit console
  2. git clone ssh:// to a Localfolder ie tmp
  3. Add sample code to your local cloned repository
           |-- MyDemoRepo
                   |-- appspec.yml
                   |-- index.html
                   |-- LICENSE.txt
                   |-- scripts
                       |-- install_dependencies
                       |-- start_server
                       |-- stop_server
  4. Commit All the files into local Directory and the push it in to AWS Code Commit Repository
    1. cd /tmp/MyDemoRepo
    2. git add -A
    3. git commit -m "Add sample application files"
    4.  git push
  5. Create an EC2 instance role
    1. Choose Create role.
    2. Under Select type of trusted entity, select AWS service. Under Choose a use case, select EC2, and then choose Next: Permissions.
    3. Search for and select the policy named AmazonEC2RoleforAWSCodeDeploy, and then choose Next: Tags.
    4. Choose Next: Review. Enter a name for the role (for example, EC2InstanceRole).
  6. Create a EC2 Instance with IAM role EC2InstanceRole and below bash script
            yum -y update
            yum install -y ruby
            yum install -y aws-cli
            cd /home/ec2-user
            aws s3 cp s3://aws-codedeploy-us-east-2/latest/install . --region us-east-2
            chmod +x ./install
            ./install auto
  7.  Create a role that allows CodeDeploy to perform deployments
    1. Choose Create role.
    2. Under Select type of trusted entity, select AWS service. Under Choose a use case, select CodeDeploy, and then choose Next: Permissions. The  AWSCodeDeployRole managed policy is already attached to the role.    
    3. Choose Next: Tags, and Next: Review.
    4. Enter a name for the role (for example, CodeDeployRole), and then choose Create role.
  8. Create an application in CodeDeploy
    1. If the Applications page does not appear, on the AWS CodeDeploy menu, choose Applications.
    2. Choose Create application.
    3. In Application name, enter MyDemoApplication.
    4. In Compute Platform, choose EC2/On-premises.
    5. Choose Create application.
  9. Create deployment group
    1.  In Deployment group name, enter MyDemoDeploymentGroup.
    2.  In Service Role, choose the service role you created earlier (for example, CodeDeployRole).
    3. Under Deployment type, choose In-place.
    4. Under Environment configuration, choose Amazon EC2 Instances. In the Key field, enter Name. In the Value field, enter the name you used to tag the instance (for example, MyCodePipelineDemo).
    5. Under Deployment configuration, choose CodeDeployDefault.OneAtaTime.
    6. Under Load Balancer, make sure Enable load balancing is not selected. You do not need to set up a load balancer or choose a target group for this  example.
    7.  Expand the Advanced section. Under Alarms, if any alarms are listed, choose Ignore alarm configuration.
    8. Choose Create deployment group.
  10. To create a CodePipeline pipeline
    1. Choose Create pipeline.
    2. In Step 1: Choose pipeline settings, in Pipeline name, enter MyFirstPipeline.
    3. In Service role, choose New service role to allow CodePipeline to create a service role in IAM.
    4. Leave the settings under Advanced settings at their defaults, and then choose Next.
    5. In Step 2: Add source stage, in Source provider, choose AWS CodeCommit. In Repository name, choose the name of the CodeCommit repository you created in Step 1: Create a CodeCommit repository. In Branch name, choose main, and then choose Next step.
      After you select the repository name and branch, a message displays the Amazon CloudWatch Events rule to be created for this pipeline.
    6. Under Change detection options, leave the defaults. This allows CodePipeline to use Amazon CloudWatch Events to detect changes in your source repository.
    7. Choose Next.
    8. In Step 3: Add build stage, choose Skip build stage, and then accept the warning message by choosing Skip again. Choose Next.
      In Step 5: Review, review the information, and then choose Create pipeline.
    9. The pipeline starts running after it is created. It downloads the code from your CodeCommit repository and creates a CodeDeploy deployment to your EC2 instance. You can view progress and success and failure messages as the CodePipeline sample deploys the webpage to the Amazon EC2 instance in the CodeDeploy deployment.