How Do You Fix the AWS CLI Error “Following required service principals [eks.amazonaws.com] were not found in the trust relationships”?

Problem scenario
You run an AWS CLI command, but you get this error:

An error occurred (InvalidParameterException) when calling the CreateNodegroup operation: Following required service principals [eks.amazonaws.com] were not found in the trust relationships of clusterRole arn:aws:iam::12345678910:role/foobar

How do you fix this?

Solution
Draft a command like this (but replace "12345677810:role/foobar" with the equivalent string in the error, and replace foobar.amazonaws.com with the service principal in the error):

aws iam list-roles --query 'Roles[?Arn==arn:aws:iam::12345678910:role/foobar]' | grep foobar.amazonaws.com

If the above command returns nothing, try the command again without the "| grep foobar.amazonaws.com". If your Role was configured correctly, you may need to open a ticket with AWS Support. If nothing is returned from the command above with the "grep", you need to modify the role. Go to the AWS Management Console, go to IAM -> Roles. Click on the role, go to "Trust Relationships" and "Edit Trust Relationship." Modify it like this:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "foo.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    },
    {
      "Effect": "Allow",
      "Principal": {
        "Service": "bar.amazonaws.com"
      },
      "Action": "sts:AssumeRole"
    }
  ]
}

Leave a comment

Your email address will not be published. Required fields are marked *