'aws codedeploy can not kubectl into aws eks

i am trying to connect to eks cluster via aws codebuild. when: kubectl get svc output:

[Container] 2022/05/13 11:27:03 Running command kubectl get svc
error: You must be logged in to the server (Unauthorized)
[Container] 2022/05/13 11:27:07 Command did not exit successfully kubectl get svc exit status 1 [Container] 2022/05/13 11:27:07 Phase complete: PRE_BUILD State: FAILED
[Container] 2022/05/13 11:27:07 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: kubectl get svc.
Reason: exit status 1

i tried : kubectl edit -n kube-system cm aws-auth

and appended the codebuild role arn and role name ->

apiVersion: v1

data:

mapRoles: |

- groups:

- system:bootstrappers

- system:nodes

rolearn: arn:aws:iam::137xxxxx:role/nodegrp-pol #(node group role)

username: system:node:{{EC2PrivateDNSName}}


rolearn: arn:NEW code build ROLE ARN ! ! ! ! ! !

username: codebuild-codebuildnew-service-role

kind: ConfigMap

metadata:

creationTimestamp: "2022-05-13T10:54:33Z"

name: aws-auth

namespace: kube-system

resourceVersion: "5668"

uid: c52f-a0f0-4266-a264-b7d746bb24

doesnt help..what can i do?how do i solve this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source