Ash-Docs
Updated for Jenkins LTS

Automating Deployments Using Jenkins & AWS S3

Imagine you are building a website. Normally, every time you make a change, you have to manually upload files. This is slow and prone to human error. In this lab, we build an Automated Pipeline. Jenkins will watch your GitHub repository and automatically deploy fresh code to AWS S3 the moment you save it!

Architecture Overview

CI/CD Architecture: GitHub to Jenkins to S3

0 Required Tools & Accounts

Ensure you have the following ready before starting the deployment lab.

Docker

Container Runtime

GitHub

Code Repository

AWS Account

Cloud Provider

Jenkins (LTS)

Automation Server

1 Setting up our Jenkins Robot

We are going to run Jenkins inside a Docker Container. Open your terminal and paste this command to start it up:

Launch Jenkins Container
docker run -d --name jenkins-server -p 8080:8080 -p 50000:50000 -v jenkins_data:/var/jenkins_home jenkins/jenkins:lts

Jenkins secures itself on the first boot. You need the initial admin password to proceed. Run this to view the logs:

Fetch Unlock Password
docker logs jenkins-server
Next Steps: Go to http://localhost:8080 in your browser, paste the password from the logs, click Install suggested plugins, and create your admin account.

2 Giving Jenkins the Right Tools

By default, Jenkins doesn't know how to talk to Amazon Web Services. We need to install the AWS Command Line tool directly inside our container.

Enter Container & Install AWS CLI
# Step 1: Drop into the container's terminal as root user
docker exec -u root -it jenkins-server /bin/bash

# Step 2: Install the AWS CLI package
apt-get update && apt-get install -y awscli

# Step 3: Exit back to your host machine
exit

3 Setting Up AWS (The Destination)

We need a place to put our website, and we need to give Jenkins a secure "ID Badge" to enter our AWS account.

AWS Configuration Checklist
  1. Create a Bucket: Log into the AWS Console, search for S3, and create a unique bucket (e.g., my-cool-website-bucket-123).
  2. Create an IAM User: Search for IAM and go to Users. Create a user named jenkins-deployer.
  3. Attach Policies: Grant this user the AmazonS3FullAccess permissions policy.
  4. Generate Keys: Go to the user's Security Credentials tab and create an Access Key for Command Line Interface use.

CRITICAL: Save Your Keys

Copy the Access Key ID and Secret Access Key shown on the AWS screen right now. You will not be able to view the secret key again once you close the window!

4 Linking AWS to Jenkins

Now we hand that ID badge over to Jenkins securely so it isn't hardcoded in our scripts.

  1. Open your Jenkins dashboard at http://localhost:8080.
  2. Navigate to Manage Jenkins -> Credentials.
  3. Click on (global), then click + Add Credentials.
  4. Set Kind to Username with password.
  5. Username: Paste your AWS Access Key ID.
  6. Password: Paste your AWS Secret Access Key.
  7. ID: Type exactly aws-credentials (We will reference this ID in code).
  8. Click Create.

5 Writing the Automation Instructions

Create a new Pipeline job in Jenkins, configure it to Poll SCM every minute (* * * * *), and paste this Groovy script into the Pipeline box. Make sure to replace your GitHub URL and Bucket Name!

Jenkinsfile Pipeline Script
pipeline {
    agent any

    environment {
        // Set this to the region where you created your S3 bucket
        AWS_DEFAULT_REGION = 'ap-south-1' 
    }

    stages {
        stage('Grab Code from GitHub') {
            steps {
                // Jenkins downloads the latest code from your main branch
                git branch: 'main', url: 'https://github.com/YourUsername/YourRepoName.git'
            }
        }

        stage('Upload to AWS S3') {
            steps {
                // Jenkins uses the secure credentials we saved earlier
                withCredentials([usernamePassword(credentialsId: 'aws-credentials', passwordVariable: 'AWS_SECRET_ACCESS_KEY', usernameVariable: 'AWS_ACCESS_KEY_ID')]) {
                    sh '''
                        echo "Starting website upload..."
                        
                        # Syncs our code files to the AWS bucket, skipping the hidden .git folder
                        aws s3 sync . s3://your-actual-bucket-name --exclude ".git/*" --delete
                        
                        echo "Upload complete! Your website is updated."
                    '''
                }
            }
        }
    }
}

6 The Final Test (Go Live)

  1. Open a code file in your GitHub repository on your computer.
  2. Make a small change (like adding a new heading) and push the commit to the main branch.
  3. Switch back to your Jenkins dashboard and watch the magic happen.
  4. Within 60 seconds, Jenkins detects the code change and triggers the build.
  5. Check your AWS S3 bucket. Your new files are officially live!

🎉 Pipeline Complete!

You have successfully bridged the gap between Source Code Management and Cloud Infrastructure.

Thanvir Assif

Created by Thanvir Assif

Cloud & DevOps Engineer | AWS Certified | Full Stack Developer. Helping professionals and enthusiasts master cloud deployments.

© 2026 Thanvir Assif. All rights reserved.