Search code examples
pythonamazon-web-servicesamazon-ec2amazon-ekseksctl

How to execute eksctl command in python script?


I would like to use the following eksctl command in a python script :

eksctl create -f managedcluster.yaml

I would like to know the python equivalent of this command such that when the python script is run, then the managed cluster gets created.


Solution

  • I think the best way to create an EKS cluster is using AWS Boto3 python library https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/eks.html#EKS.Client.create_cluster .

    But the fastest way in your case is to use the subprocess library.

    Ex :

    import subprocess
    output = subprocess.check_output("eksctl create -f managedcluster.yaml", shell=True)
    

    Best,