USD ($)
$
United States Dollar
Euro Member Countries
India Rupee
د.إ
United Arab Emirates dirham
ر.س
Saudi Arabia Riyal

Using GitHub Actions and Jenkins on AWS

Lesson 15/50 | Study Time: 40 Min

AWS CodePipeline and CodeBuild are solid choices for a fully AWS-native CI/CD setup. But in the real world, many teams use GitHub Actions or Jenkins — either by preference, existing investment, or because their workflow spans multiple cloud providers. 

GitHub Actions on AWS

GitHub Actions is GitHub's built-in CI/CD platform. Workflows are defined in YAML files stored inside your repository under .github/workflows/. They trigger automatically on events — a push, a pull request, a schedule, or a manual trigger.


Connecting GitHub Actions to AWS

To deploy to AWS from GitHub Actions, you need to give it permission to interact with your AWS account. There are two ways to do this.

Option A — IAM User Access Keys (Simple but less secure)

Store your AWS credentials as GitHub Secrets and reference them in the workflow:


yaml

- name: Configure AWS credentials

  uses: aws-actions/configure-aws-credentials@v2

  with:

    aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}

    aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

    aws-region: ap-south-1

```

**Option B — OpenID Connect (OIDC) — Recommended**


OIDC lets GitHub Actions assume an IAM Role directly — no long-lived access keys stored anywhere. This is the most secure approach.

```

AWS Console → IAM → Identity Providers → Add Provider

→ Provider type: OpenID Connect

→ Provider URL: https://token.actions.githubusercontent.com

→ Audience: sts.amazonaws.com


Then create an IAM Role that trusts this identity provider and attach the permissions your workflow needs. Reference it in your workflow:


A Complete GitHub Actions Workflow for AWS


yaml


# .github/workflows/deploy.yml

name: Build and Deploy to AWS


on:

  push:

    branches: [main]


permissions:

  id-token: write

  contents: read


jobs:

  deploy:

    runs-on: ubuntu-latest


    steps:

      - name: Checkout code

        uses: actions/checkout@v3


      - name: Set up Python

        uses: actions/setup-python@v4

        with:

          python-version: '3.11'


      - name: Install dependencies and run tests

        run: |

          pip install -r requirements.txt

          pytest tests/


      - name: Configure AWS credentials

        uses: aws-actions/configure-aws-credentials@v2

        with:

          role-to-assume: arn:aws:iam::123456789:role/GitHubActionsDeployRole

          aws-region: ap-south-1


      - name: Deploy to S3

        run: |

          zip -r app.zip src/

          aws s3 cp app.zip s3://my-deployment-bucket/app.zip


      - name: Trigger CodeDeploy

        run: |

          aws deploy create-deployment \

            --application-name my-app \

            --deployment-group-name production \

            --s3-location bucket=my-deployment-bucket,key=app.zip,bundleType=zip


Jenkins on AWS

Jenkins is an open-source automation server — one of the oldest and most widely used CI/CD tools in the world. Unlike GitHub Actions, Jenkins is self-hosted — you run it on your own infrastructure. On AWS, this typically means running Jenkins on an EC2 instance.

Jenkins is highly flexible and has thousands of plugins, making it suitable for complex, customised pipelines. However, it requires more setup and ongoing maintenance than managed services.


Setting Up Jenkins on AWS EC2


bash

# Launch an EC2 instance (Amazon Linux 2 or Ubuntu)

# Then SSH into it and install Jenkins


# Install Java (Jenkins requires it)

sudo apt update

sudo apt install -y openjdk-17-jdk


# Add Jenkins repository and install

curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | \

  sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null


echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \

  https://pkg.jenkins.io/debian binary/ | \

  sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null


sudo apt update

sudo apt install -y jenkins

sudo systemctl start jenkins

sudo systemctl enable jenkins

```


Access Jenkins at `http://your-ec2-public-ip:8080`.


### Connecting Jenkins to AWS


Attach an IAM Role to your EC2 instance with the permissions Jenkins needs — S3 access, CodeDeploy access, ECR access, and so on. Because Jenkins runs on EC2, it inherits the instance role automatically — no access keys needed.

```

AWS Console → EC2 → Select your Jenkins instance

→ Actions → Security → Modify IAM Role

→ Attach your Jenkins IAM Role


Jenkinsfile — Defining Your Pipeline as Code

Jenkins pipelines are defined in a file called Jenkinsfile stored in your repository root. This is the Jenkins equivalent of buildspec.yml or a GitHub Actions workflow file.


groovy


pipeline {

    agent any


    environment {

        AWS_REGION = 'ap-south-1'

        S3_BUCKET  = 'my-deployment-bucket'

    }


    stages {

        stage('Checkout') {

            steps {

                checkout scm

            }

        }


        stage('Install and Test') {

            steps {

                sh 'pip install -r requirements.txt'

                sh 'pytest tests/ --verbose'

            }

        }


        stage('Build') {

            steps {

                sh 'zip -r app.zip src/'

            }

        }


        stage('Deploy to S3') {

            steps {

                sh 'aws s3 cp app.zip s3://${S3_BUCKET}/app.zip'

            }

        }


        stage('Trigger CodeDeploy') {

            steps {

                sh '''

                aws deploy create-deployment \

                  --application-name my-app \

                  --deployment-group-name production \

                  --s3-location bucket=${S3_BUCKET},key=app.zip,bundleType=zip \

                  --region ${AWS_REGION}

                '''

            }

        }

    }


    post {

        success {

            echo 'Pipeline completed successfully.'

        }

        failure {

            echo 'Pipeline failed. Check the logs.'

        }

    }

}


GitHub Actions vs. Jenkins vs. CodePipeline

Drew Collins

Drew Collins

Product Designer
Profile

Class Sessions

1- What is DevOps? Principles, Culture, and Practices 2- The DevOps Lifecycle 3- Introduction to Cloud Computing 4- AWS Global Infrastructure 5- Core AWS Services Overview 6- Git Fundamentals 7- Branching Strategies 8- Pull Requests and Code Review Best Practices 9- Integrating Git with AWS CodeCommit and GitHub 10- Managing Secrets and Sensitive Files in Repositories 11- What is CI/CD? 12- Building Pipelines with AWS CodePipeline and CodeBuild 13- Automated Testing in CI 14- Deployment Strategies 15- Using GitHub Actions and Jenkins on AWS 16- Why Infrastructure as Code (IaC)? 17- AWS CloudFormation 18- Terraform on AWS 19- AWS Cloud Development Kit (CDK) 20- IaC Best Practices 21- Docker Fundamentals 22- Amazon ECR 23- Deploying Containers with Amazon ECS 24- Kubernetes Basics and Amazon EKS 25- Integrating Containers into CI/CD Pipelines 26- Serverless Computing Concepts and Use Cases 27- Building and Deploying AWS Lambda Functions 28- Event-Driven Automation with Amazon EventBridge 29- Orchestrating Workflows with AWS Step Functions 30- API Gateway Integration for Serverless APIs 31- Introduction to MLOps 32- Training and Deploying Models with Amazon SageMaker 33- Automating ML Pipelines with SageMaker Pipelines 34- Using Amazon CodeWhisperer and AI Tools for Code Automation 35- AI-Powered Testing, Anomaly Detection, and Incident Prediction 36- Observability Fundamentals 37- Amazon CloudWatch 38- Distributed Tracing with AWS X-Ray 39- Centralised Logging with Amazon OpenSearch Service 40- Setting Up Automated Alerts and Incident Response Workflows 41- Shift-Left Security 42- IAM Roles, Policies, and Least-Privilege Access 43- Static Code Analysis and Vulnerability Scanning in CI/CD 44- AWS Security Hub, GuardDuty, and Config for Compliance 45- Secrets Management with AWS Secrets Manager and Parameter Store 46- AWS Well-Architected Framework 47- Auto Scaling and Elastic Load Balancing for Resilience 48- Cost Monitoring with AWS Cost Explorer and Budgets 49- Disaster Recovery Strategies 50- Preparing Your Project for Production

Sales Campaign

Sales Campaign

We have a sales campaign on our promoted courses and products. You can purchase 1 products at a discounted price up to 15% discount.