amazon-web-servicesgithubamazon-ec2github-actions

AWS EC2 instance was not able to register itself in GitHub as a new self-hosted runner


I am trying to register an AWS EC2 instance as a new self hosted runner in Github but get this error:

GitHub Registration Token is received
AWS EC2 instance i-abcd is started
AWS EC2 instance i-abcd is up and running
Waiting 30s for the AWS EC2 instance to be registered in GitHub as a new self-hosted runner
Checking every 10s if the GitHub self-hosted runner is registered
Checking...
Checking...
Error: GitHub self-hosted runner registration error
Checking...
Error: A timeout of 5 minutes is exceeded. Your AWS EC2 instance was not able to register itself in GitHub as a new self-hosted runner.

I am using this to create my EC2 GitHub runner.

The code in my workflow:

      - name: Start EC2 Runner
        id: start-ec2-runner
        uses: machulav/ec2-github-runner@v2
        with:
          mode: start
          github-token: ${{ secrets.PAT_CLASSIC }}
          ec2-image-id: ${{ secrets.EC2_IMAGE_ID }}
          ec2-instance-type: m5a.xlarge
          subnet-id: ${{ secrets.EC2_SUBNET_ID }}
          security-group-id: ${{ secrets.EC2_SECURITY_GROUP_ID }}

My IAM role policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "EC2Permissions",
            "Effect": "Allow",
            "Action": [
                "ec2:DescribeInstances",
                "ec2:RunInstances",
                "ec2:StartInstances",
                "ec2:StopInstances",
                "ec2:TerminateInstances",
                "ec2:CreateTags",
                "tag:TagResources"
            ],
            "Resource": "*"
        }
    ]
}

I have verified that the credentials added to the secrets in Github are right. In the IAM console in AWS I have verified that the credentials are being used by the EC2 instance when it gets started up and running. Also, the EC2 instance displayed in the CI is getting created in AWS EC2 with the correct AMI ID, Subnet ID and Security Group ID. For my Security Group I have allowed all outbound traffic.

I have regenerated my PAT Token for this repo level self hosted runner and authorized it with the necessary permissions -

read-public key
workflow
repo
read-repo hook

What am I missing here?


Solution

  • Got it working, reason for the error was that Github doesn't support Amazon Linux AMI for self-hosted runners. This has more details