<p>I have a role which has full privilege to access EKS, Ec2, IAM which is attached to an Ec2 Instance.</p>
<p>I am trying to access my EKS cluster from this Ec2 Instance. I did add the Ec2 instance arn like below to the Trusted relationship of the role which the instance assumes as well. However, still I get the error like below when trying to access the cluster using <code>kubectl</code> from cli inside the Ec2 instance.</p>
<p>I have tried below to obtain the kube config written to the instance hoe directory from which I execute these commands.</p>
<pre><code>aws sts get-caller-identity

$ aws eks update-kubeconfig --name eks-cluster-name --region aws-region --role-arn arn:aws:iam::XXXXXXXXXXXX:role/testrole
</code></pre>
<p>Error I'm getting:</p>
<pre><code>error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:sts::769379794363:assumed-role/dev-server-role/i-016d7738c9cb84b96 is not authorized to perform: sts:AssumeRole on resource xxx
</code></pre>

<p>Community wiki answer for better visibility.</p>
<p>The problem is solved by taking a good tip from the comment:</p>
<blockquote>
<p>Don't specify <code>role-arn</code> if you want it to use the instance profile.</p>
</blockquote>
<p>OP has confirmed:</p>
<blockquote>
<p>thanks @jordanm that helped</p>
</blockquote>
