Lambda to access other account EKS clusters

0

We look to create a lambda function (in Python ideally ) which need to execute every hour and check the running pods in different Account's eks cluster.

Had a look at the below solution ,but the solution support within the pod environment and need SA within that.

https://docs.aws.amazon.com/eks/latest/userguide/cross-account-access.html

Any suggestion or ideas will helpful.

已提問 1 年前檢視次數 2061 次
1 個回答
0

Hello,

Let's assume your EKS cluster is in Account A, and your Lambda function is in Account B.

Networking:

In order to access your EKS cluster from Account B, your EKS cluster will either need to be enabled with public access endpoint, or you will have to use VPC peering or transit gateway and connect the EKS cluster VPC in Account A with the VPC associated with your Lambda in Account B.

IAM:

  • Create an IAM role in your Account A and add it to the aws-auth configmap of your EKS cluster to allow the required permissions to this IAM role. Also, make sure that the IAM role has the eks:DescribeCluster permissions.
  • Allow the Lambda execution role of your Account B to perform sts:AssumeRole action in the above created IAM role's trust-relationship. This will allow your Lambda function in Account B to assume the IAM role in Account A.

Lambda code:

  • Perform sts:AssumeRole operation on the IAM role in Account A to assume that role and get its credentials.
  • Perform eks:DescribeCluster operation to get the cluster details.
  • Create the kubeconfig file using the DescribeCluster output. Please refer this document to understand how to manually create the kubeconfig using the cluster details from the DescribeCluster output. I found this stackoverflow post that has the python code to create the kubeconfig file.

Now that the kubeconfig file is setup, you can perform API operations on your EKS cluster.

Hope this helps!

profile pictureAWS
支援工程師
已回答 1 年前
  • Hello Venkat, Thanks for your suggestion will try this and feedback

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南