Introduction

Automating deployment processes enhances efficiency, reduces errors, and ensures seamless application updates. This guide provides a step-by-step approach to setting up an automated deployment pipeline using AWS CodeCommit, AWS CodePipeline, and Amazon S3 to host a static website.

Prerequisites

Before beginning, ensure the following requirements are met:

  • An AWS account with necessary permissions
  • AWS CLI installed and configured
  • A static website ready for deployment
  • IAM roles with required permissions for CodeCommit, CodePipeline, and S3

Step 1: Create an AWS CodeCommit Repository

  1. Navigate to the AWS Management Console.
  2. Open the CodeCommit service and create a new repository.
  3. Clone the repository to a local machine using Git:
  4. git clone https://git-codecommit.<region>.amazonaws.com/v1/repos/<repository-name>
  5. Add static website files to the repository and commit changes:


git add .

git commit -m “Initial commit”

  1. git push origin main

Step 2: Configure an S3 Bucket for Static Website Hosting

  1. Open the S3 service in the AWS Console.
  2. Create a new S3 bucket and enable Static Website Hosting.
  3. Set up the bucket policy to allow public read access:


{

  “Version”: “2012-10-17”,

  “Statement”: [

    {

      “Effect”: “Allow”,

      “Principal”: “*”,

      “Action”: “s3:GetObject”,

      “Resource”: “arn:aws:s3:::<bucket-name>/*”

    }

  ]

  1. }
  2. Note the endpoint URL of the hosted static website.

Step 3: Set Up AWS CodePipeline

  1. Navigate to the CodePipeline service.
  2. Create a new pipeline and select AWS CodeCommit as the source provider.
  3. Choose the repository created earlier and select the branch (e.g., main).
  4. Configure the build stage using AWS CodeBuild (optional for preprocessing).
  5. Add a deploy stage and select Amazon S3 as the deployment provider.
  6. Specify the S3 bucket where the static website files should be deployed.
  7. Review and create the pipeline.

Step 4: Test the Deployment Pipeline

  1. Make changes to the static website locally.
  2. Commit and push the changes to the CodeCommit repository:


git add .

git commit -m “Updated website content”

  1. git push origin main
  2. The pipeline automatically detects changes and deploys them to the S3 bucket.
  3. Verify the changes by accessing the static website URL.

Conclusion

By leveraging AWS CodeCommit, AWS CodePipeline, and Amazon S3, a fully automated deployment pipeline can be established for seamless updates to a static website. This approach enhances development workflows, ensures consistency, and eliminates manual deployment efforts.