In this section, you will configure the necessary execution permissions across two distinct boundaries: the Operating System level (Linux Sudoers) and the AWS IAM role. This ensures that the GitLab Runner can build Docker images and invoke AWS ECS APIs during automated deployment runs.
Our CI/CD pipeline runs directly on an EC2 build instance using the Shell Executor. To complete pipeline tasks, the runner requires authorized access at two levels:
Because CI/CD jobs run non-interactively, any command requiring sudo will fail if a password prompt is triggered. We must configure passwordless sudo (NOPASSWD) for the gitlab-runner account.
Open the sudoers configuration using the visudo command:
sudo visudo
Scroll to the bottom of the file and append the following entry:
gitlab-runner ALL=(ALL) NOPASSWD:ALL

Save and close the editor:
Ctrl + O, then Enter to save, and Ctrl + X to exit.Esc, type :wq, and press Enter.Test that the gitlab-runner user can execute privileged commands without entering a password:
sudo -u gitlab-runner sudo whoami
Expected terminal output:
root
If the command outputs root without prompting for a password, your sudoers configuration is correct.
Open the AWS Management Console and navigate to EC2 → Instances.
Select your running build instance.
In the Details pane below, look for IAM role:

The build instance already has ECR read/write access via CustomRWECRRole. To deploy containerized services, it also requires permissions to manage ECS Task Definitions and trigger service updates.
In the AWS Management Console search bar, enter IAM and open the IAM Dashboard.
In the left navigation pane, select Roles.
In the search box, type CustomRWECRRole and click on the role name to view its configuration.

In the Permissions tab, click Add permissions → Attach policies.

Search for and select the following AWS managed policies:
AmazonEC2FullAccess, check the box next to it.AmazonECS_FullAccess, check the box next to it.

Your EC2 instance now has the necessary permissions to build Docker images and deploy containerized services to ECS.
