Jenkins in AWS

Here’s how we can quickly launch a Jenkins instance on AWS EC2:

🚀 Launch Jenkins on AWS EC2

  1. Login to AWS Console and go to the EC2 service. Click “Launch Instance.”
  2. Select an Amazon Machine Image:
    • Amazon Linux 2 AMI (HVM), SSD Volume Type
  3. Choose Instance Type:
    • t2.micro (free tier eligible)
  4. Configure Instance Details:
    • Keep defaults. In “Advanced Details,” add the following user data script to install and start Jenkins automatically:
    #!/bin/bash
    $wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo  
    $rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
    $yum install -y java jenkins
    $chkconfig --add jenkins
    $systemctl start jenkins
    
  5. Add Storage:
    • We can keep the default or adjust as needed.
  6. Add Tags:
    • (Optional) Add tags for organization.
  7. Configure Security Group:
    • Allow SSH (port 22, source: My IP)
    • Allow HTTP (port 8080, source: My IP or 0.0.0.0/0 for public access)

    security groups

  8. Review and Launch:
    • Select an existing key pair or create a new one for SSH access.

🌐 Access Jenkins

🔑 Unlock Jenkins

When Jenkins starts, it will prompt for an administrator password. We retrieve it by connecting to our instance:

# Connect to the instance
ssh -i <key_name>.pem ec2-user@<aws-instance-public-dns>

# Get the Jenkins admin password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

We’re now ready to finish Jenkins setup in our browser!