AWS CodePipeline (CI/CD Pipeline)

CICD Pipeline with CodeCommit CodeBuild and CodeDeploy

CodeCommit Demo

Welcome to this comprehensive tutorial on using AWS CodeCommit as your source stage in a CI/CD pipeline. You’ll learn how to:

  • Create a CodeCommit repository
  • Upload and manage files
  • Work with branches
  • Open and merge a pull request

Feel free to follow along in your own AWS account!

Note

AWS CodeCommit seamlessly integrates with other AWS Developer Tools. You can also connect it to your local Git client for advanced workflows.


Table of Contents

  1. Create a Repository
  2. Upload Files
    • appspec.yml
    • before-install.bat
    • index.html
  3. Branch Management
  4. Pull Request Workflow
  5. Merge and Verify
  6. Conclusion & References

Create a Repository

  1. Sign in to the AWS Management Console and open CodeCommit.
  2. Click Create repository.
  3. Provide a name (e.g., MyDemoRepo) and an optional description.
  4. Click Create.

The image shows the AWS CodeCommit interface with an empty repositories list and an option to create a new repository. The navigation menu on the left includes options for various AWS Developer Tools.


Upload Files

Start by adding the deployment configuration and application assets.

FileDescription
appspec.ymlDefines deployment hooks and file mappings
before-install.batInstalls IIS on Windows target
index.htmlSample HTML page for testing deployment

1. Upload appspec.yml

  1. In the repository, click Add file > Upload file.
  2. Select your local appspec.yml.
  3. Enter author name, email, commit message (optional), and click Commit changes.

The image shows an AWS CodeCommit interface where a user is preparing to commit changes to a file named "appspec.yml" in a repository called "MyDemoRepo." The interface includes fields for author name, email address, and an optional commit message.

version: 0.0
os: windows
files:
  - source: \index.html
    destination: C:\inetpub\wwwroot
hooks:
  BeforeInstall:
    location: \before-install.bat
    timeout: 900

2. Upload before-install.bat

  1. Click Add file > Upload file.
  2. Choose before-install.bat from your machine.
  3. Fill in author details and click Commit changes.

The image shows an AWS CodeCommit interface where a file named "before-install.bat" is being uploaded to a repository called "MyDemoRepo." The interface includes fields for author name, email address, and an optional commit message.

REM Install Internet Information Server (IIS).
c:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe -Command Import-Module -Name ServerManager
c:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe -Command Install-WindowsFeature Web-Server

3. Upload index.html

  1. Click Add file > Upload file.
  2. Select index.html.
  3. Add author info and commit.

The image shows an AWS CodeCommit interface where a file named "index.html" is being uploaded to a repository called "MyDemoRepo." It includes fields for author name, email address, and an optional commit message.

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Sample Deployment</title>
  <style>
    body {
      color: #ffffff;
      background-color: #0073f3;
      font-family: Arial, sans-serif;
      font-size: 14px;
    }
    h1 { font-size: 500%; margin-bottom: 0; }
    h2 { font-size: 200%; margin-bottom: 0; }
  </style>
</head>
<body>
  <h1>Deployment Successful</h1>
  <h2>Welcome to AWS CodeCommit</h2>
</body>
</html>

Branch Management

  1. Select Branches in the sidebar. You’ll see the default branch named main.
  2. Click Create branch, enter branch2 as the new branch name, and choose main as the source.
  3. Click Create.

The image shows the AWS CodeCommit interface for a repository named "MyDemoRepo," displaying the branches section with a default branch named "main" and a recent commit message "Added index.html."

The image shows an AWS CodeCommit interface with a repository named "MyDemoRepo" displaying two branches, "main" and "branch2," both with recent commits adding an "index.html" file. A success message indicates that "branch2" has been created.

Best Practice

Use descriptive branch names that reflect the feature or fix you’re working on.

Edit a File in branch2

  1. Switch to branch2.
  2. Open appspec.yml and click Edit.
  3. Add a comment line at the end, then commit your changes.

The image shows an AWS CodeCommit interface where changes are being committed to a branch. It includes fields for author name, email address, and an optional commit message.

version: 0.0
os: windows
files:
  - source: \index.html
    destination: C:\inetpub\wwwroot
hooks:
  BeforeInstall:
    location: \before-install.bat
    timeout: 900
# Demo Testing

Pull Request Workflow

  1. Click Pull requests in the sidebar.
  2. Click Create pull request.
  3. Set Source to branch2 and Destination to main, then click Compare.

The image shows the AWS CodeCommit interface for creating a pull request, indicating that the branches "branch2" and "main" are mergeable with no conflicts.

Review the changes:

 BeforeInstall:
   location: \before-install.bat
   timeout: 900
+  # Demo Testing
  1. Enter a title like Demo Pull Request and an optional description.
  2. Click Create pull request.

The image shows an AWS CodeCommit interface with a "Demo Pull Request" open. It indicates that the pull request has been successfully created, with no approval rules or merge conflicts.


Merge and Verify

  1. In the pull request view, click Merge.
  2. Select Fast-forward merge and confirm.
  3. Optionally uncheck Delete branch if you wish to preserve branch2.
# You can also merge locally:
git fetch origin
git checkout main
git merge --ff-only origin/branch2

Warning

Deleting a branch removes its history in the console view. Make sure you no longer need it before deleting.

Verify on main

Switch back to main and open appspec.yml to see the merged comment:

The image shows the AWS CodeCommit interface with a repository named "MyDemoRepo" containing three files: `appspec.yml`, `before-install.bat`, and `index.html`. The left sidebar displays various options like Code, Pull requests, and Branches.

version: 0.0
os: windows
files:
  - source: \index.html
    destination: C:\inetpub\wwwroot
hooks:
  BeforeInstall:
    location: \before-install.bat
    timeout: 900
# Demo Testing

Conclusion & References

You’ve successfully created a CodeCommit repository, uploaded files, managed branches, and completed a pull request merge—all via the AWS Console.

Next, explore how to integrate CodeCommit with AWS CodeBuild and CodeDeploy for automated builds and deployments.

Watch Video

Watch video content

Practice Lab

Practice lab

Previous
Repositories