How I turned aws ec2 into an aws gitlab-runner


A GitLab Runner is an open-source application used to run jobs and send the results back to GitLab in a CI/CD (Continuous Integration/Continuous Deployment) pipeline. GitLab Runner executes the steps defined in your .gitlab-ci.yml
file. for example:
Building your code
Running tests
Deploying applications
GitLab Runner uses executors to determine how to run a job for example shell, docker etc
Objective
- To set up an AWS EC2 instance as a GitLab Runner.
Requirements
- A server(vps, ec2, droplet)with at least 4gb of RAM
In order to be able to follow up on this tutorial you need practice. That means you need a linux/macbook machine. If yo are like me using windows don’t worry I got you covered. I will be using vagrant. You can check out how to install vagrant on their official website Vagrant Get Started Tutorial by HashiCorp or gitbash.
To get started you need to
- Login to your gitlab account
Click on settings
Click on CI/CD
- Click on Runners
- Click on Create project runner
- Type the tags (tags identifies each runner)
- Scroll down and click on create
You will see an interface like this
- Copy the command
- After you copy the first command paste it on you command line. I will paste mine on my vagrant (ubuntu 20) command line
To install gitlab-runner
Open gitbash or vagrant
ssh into the server
ssh -i file.pem ubuntu@ipaddress
- curl the script file
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
- Update your operating system
sudo apt update
sudo apt install gitlab-runner -y
- Start and enable the service
sudo systemctl enable gitlab-runner
sudo systemctl start gitlab-runner
- To check gitlab-runner status
gitlab-runner status
Paste the step 1 code on the terminal
Press Enter twice
Type the executor you want to use (in this case I used shell)
- You can see that it is configured successfully
- You can go back to your gitlab interface to verify. You can now run gitlab-ci jobs on the self hosted ec2 runner
Subscribe to my newsletter
Read articles from Oshaba Samson directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Oshaba Samson
Oshaba Samson
I am a software developer with 5 years + experience. I have working on web apps ecommerce, e-learning, hrm web applications and many others