jueves, 26 de septiembre de 2024

aws cli: List instances

Nice way to list instances from aws cli


alejandrogarcia@MacBook-Air-de-Alejandro Downloads % aws --profile myprofileforaws ec2 describe-instances  \

--query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name}" --output table

-------------------------------------

|         DescribeInstances         |

+----------+------------+-----------+

|   Name   | PublicIP   |  Status   |

+----------+------------+-----------+

minikubeNone      |  stopped  |

ansibleNone      |  stopped  |

+----------+------------+-----------+



Another way is with filters parameter, very useful.


aws ec2 describe-instances \ --query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name}" \ --filters Name=instance-state-name,


And to check more details of the instances:

alejandrogarcia@MacBook-Air-de-Alejandro Downloads % aws --profile myprofileforaws ec2 describe-instances  \

--query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name,Instance:InstanceId}" --output table 

------------------------------------------------------------

|                     DescribeInstances                    |

+----------------------+-----------+-----------+-----------+

|       Instance       |   Name    | PublicIP  |  Status   |

+----------------------+-----------+-----------+-----------+

i-08088aaa07c35fcebminikubeNone     |  stopped  |

i-0c21f4ff53460944dansible  |  None     |  stopped  |

+----------------------+-----------+-----------+-----------+



Or to check the public dns name:


alejandrogarcia@MacBook-Air-de-Alejandro Downloads % aws --profile myprofileforaws ec2 describe-instances  \

--query "Reservations[*].Instances[*].{PublicIP:PublicIpAddress,Name:Tags[?Key=='Name']|[0].Value,Status:State.Name,Instance:InstanceId,DNS:PublicDnsName}" --output table              

--------------------------------------------------------------------------------------------------------------

|                                              DescribeInstances                                             |

+--------------------------------------------+----------------------+-----------+----------------+-----------+

|                     DNS                    |      Instance        |   Name    |   PublicIP     |  Status   |

+--------------------------------------------+----------------------+-----------+----------------+-----------+

ec2-34-203-246-26.compute-1.amazonaws.comi-08088aaa07c35fcebminikube34.203.246.26running  |

|                                            |  i-0c21f4ff53460944dansible  |  None          |  stopped  |

+--------------------------------------------+----------------------+-----------+----------------+-----------+


To start a particular instance:

alejandrogarcia@MacBook-Air-de-Alejandro Downloads % aws --profile myprofileforaws ec2 start-instances --instance-ids i-08088aaa07c35fceb 

{

    "StartingInstances": [

        {

            "CurrentState": {

                "Code": 0,

                "Name": "pending"

            },

            "InstanceId": "i-08088aaa07c35fceb",

            "PreviousState": {

                "Code": 80,

                "Name": "stopped"

            }

        }

    ]

}




To check a particular instance dns name:

alejandrogarcia@MacBook-Air-de-Alejandro Downloads % aws --profile myprofileforaws ec2 describe-instances --instance-ids i-08088aaa07c35fceb |grep PublicDnsName

                    "PublicDnsName": "ec2-34-203-246-26.compute-1.amazonaws.com",

                                "PublicDnsName": "ec2-34-203-246-26.compute-1.amazonaws.com",

                                        "PublicDnsName": "ec2-34-203-246-26.compute-1.amazonaws.com",




No hay comentarios:

Publicar un comentario