How to list pods and nodes using AWS API?

10/14/2021

I have a cluster in AWS EKS and 1 node group which has 1 node, how to display node and pods using aws api? I have credentials for service account, how to use these credentials in an API and get list of available nodes and pods? when I try to execute command kubectl get pods it shows an error:

An error occurred (AccessDenied) when calling the AssumeRole operation: User: >arn:aws:iam:xxxx:user/xx is not authorized to perform: sts:AssumeRole on resource: >arn:aws:iam::xx:user/xx

-- dev
amazon-eks
amazon-web-services
kubernetes
kubernetes-pod

1 Answer

10/14/2021

You need to do two things before accessing your cluster.

  1. Add your IAM Roles or Users to the aws-auth ConfigMap to configure who can access the cluster. The IAM role that was used for creating the cluster, already have access.

  2. When accessing the cluster, you must authenticate and populate your kubeconfig. This can be done with aws eks update-kubeconfig command:

    aws eks update-kubeconfig --name <my-cluster-name>

-- Jonas
Source: StackOverflow