Quick start

Know How Guide and Hands on Guide for AWS

Quick start

Two-stage pipeline

How to build it?

  1. Create a S3 bucket ray-awscodepipeline-demobucket and enable the versioning

  2. Upload the sample application and upload to S3 bucket

aws s3 cp SampleApp_Linux.zip s3://ray-awscodepipeline-demobucket/source/SampleApp_Linux.zip --region ap-southeast-1 --profile global
  1. Create an instance role for EC2 ec2-codeX-instance-profile with permission AmazonEC2RoleforAWSCodeDeploy

  2. Create 2 EC2 Linux instances and install the CodeDeploy agent:

#!/bin/bash
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

Create other EC2 instance, but with Tag: Name:MyCodePipelineDemoProduction

  1. Create an application MyDemoApplication in CodeDeploy
    • Choose EC2/On-premises as Compute Platform
  2. Create Deployment group MyDemoDeploymentGroup
    • MyCodeDeployRole as Service Role, follow the guide create-service-role-for-codedeploy
    • Deployment type: In-place
    • Environment configuration, choose Amazon EC2 Instances with tag MyCodePipelineDemo
    • Deployment configuration, choose CodeDeployDefault.OneAtaTime
  3. Create two-stage pipeline in CodePipeline
    • pipeline name: two-stage-pipeline
    • Source: Provider: S3, Bucket: ray-awscodepipeline-demobucket, Object Key: source/SampleApp_Linux.zip
    • Skip build stage
    • Deploy provider: AWS CodeDeploy in the same region, Application name: MyDemoApplication, Deployment group: MyDemoDeploymentGroup
  4. Verify your pipeline ran successfully and access the Public DNS of your EC2 instances in your browser to view the index page for the sample application

Extension - Update the two-stage-pipeline to staging deployment and production deployment

  1. Create a second deployment group in CodeDeploy for MyDemoApplication Application
    • name: CodePipelineProductionFleet
    • Others setting follow up the first deployment group but specify the EC2 instance with tag Name:MyCodePipelineDemoProduction
  2. Add the deployment group CodePipelineProductionFleet as third stage in your pipeline
    • Add stage immediately after the Deploy stage with name Production
    • Add action group with name Deploy-Production, Action provider as AWS CodeDeploy
    • Input artifacts: SourceArtifact, Application name: MyDemoApplication, Deployment group: CodePipelineProductionFleet. Choose Save.
  3. Modify the code
    unzip SampleApp_Linux.zip -d SampleApp_Linux
    Modify the index.html
    zip -r SampleApp_Linux.zip SampleApp_Linux
    aws s3 cp SampleApp_Linux.zip s3://ray-awscodepipeline-demobucket/source/SampleApp_Linux.zip --region ap-southeast-1 --profile global
    
  4. Trigger the new pipeline The pipeline should triggered automatically by S3 upload new version source package. Otherwise, you can use the below command to trigger the code.
    aws codepipeline start-pipeline-execution --name two-stage-pipeline --region ap-southeast-1 --profile global
    

Two-stage pipeline with CodeCommit as Source Repository

  1. Create CodeCommit Repository with name MyDemoRepo
  2. Clone the CodeCommit Repository
git clone ssh://git-codecommit.ap-southeast-1.amazonaws.com/v1/repos/MyDemoRepo
cd SampleApp_Linux/
mv * ~/MyDemoRepo/
cd ~/MyDemoRepo/

tree
.
├── appspec.yml
├── index.html
├── LICENSE.txt
└── scripts
    ├── install_dependencies
    ├── start_server
    └── stop_server

1 directory, 6 files

git add -A
git commit -m "Add sample application files"
git push
  1. Modify the two-stage-pipeline Pipeline
    • Modify the Source stage. Source provider: AWS CodeCommit, Repository name: MyDemoRepo, Branch name: master.
    • Modify the source code index.html ```html
Sample Deployment

Congratulations

This application was updated using CodePipeline, CodeCommit, and CodeDeploy.

Learn more:

CodePipeline User Guide

CodeCommit User Guide

CodeDeploy User Guide


```bash
git commit -am "Updated sample application files"
git push
  1. Verify your pipeline ran successfully and access the Public DNS of your EC2 instances in your browser to view the index page for the sample application