Quantcast
Channel: Sameer Shaik. B.E,M.S,M.B.A,P.M.P,C.S.M
Viewing all articles
Browse latest Browse all 191

AWS start/stop/get status EC2 instance using aws cli

$
0
0
After you setup the aws cli, you can use the cli to start/stop the instances or any action that you can do via the management console to manage the resources.

Below using aws cli you can start/stop/get status of the instances...

shaiks@shaikslinux>aws ec2 start-instances  --instance-ids i-01**********fe
STARTINGINSTANCES       i-01***********fe
CURRENTSTATE    16      running
PREVIOUSSTATE   16      running



shaiks@shaikslinux>aws ec2 describe-instance-status  --instance-ids i-01*********fe --output table
-----------------------------------------------
|           DescribeInstanceStatus            |
+---------------------------------------------+
||             InstanceStatuses              ||
|+-------------------+-----------------------+|
|| AvailabilityZone  |      InstanceId       ||
|+-------------------+-----------------------+|
||  us-east-2c       |  i-01*******fe  ||
|+-------------------+-----------------------+|
|||              InstanceState              |||
||+----------------+------------------------+||
|||      Code      |         Name           |||
||+----------------+------------------------+||
|||  16            |  running               |||
||+----------------+------------------------+||
|||             InstanceStatus              |||
||+-------------------------+---------------+||
|||  Status                 |  ok           |||
||+-------------------------+---------------+||
||||                Details                ||||
|||+-----------------------+---------------+|||
||||         Name          |    Status     ||||
|||+-----------------------+---------------+|||
||||  reachability         |  passed       ||||
|||+-----------------------+---------------+|||
|||              SystemStatus               |||
||+-------------------------+---------------+||
|||  Status                 |  ok           |||
||+-------------------------+---------------+||
||||                Details                ||||
|||+-----------------------+---------------+|||
||||         Name          |    Status     ||||
|||+-----------------------+---------------+|||
||||  reachability         |  passed       ||||
|||+-----------------------+---------------+|||


shaiks@shaikslinux>aws ec2 stop-instances  --instance-ids i-01**************e
STOPPINGINSTANCES       i-01********fe
CURRENTSTATE    64      stopping
PREVIOUSSTATE   16      running


shaiks@shaikslinux>aws ec2 describe-instance-status  --instance-ids i-01********e --output table
------------------------
|DescribeInstanceStatus|
+----------------------+





To
shaiks@shaikslinux>aws ec2 describe-instances --output table
------------------------------------------------------------------------------
|                              DescribeInstances                             |
+----------------------------------------------------------------------------+
||                               Reservations                               ||
|+------------------------------+-------------------------------------------+|
||  OwnerId                     |  7*********20                             ||
||  ReservationId               |  r-********3362                      ||
|+------------------------------+-------------------------------------------+|
|||                                Instances                               |||
||+------------------------+-----------------------------------------------+||
|||  AmiLaunchIndex        |  0                                            |||
|||  Architecture          |  x86_64                                       |||
|||  ClientToken           |  H**********2538                           |||
|||  EbsOptimized          |  False                                        |||
|||  EnaSupport            |  True                                         |||
|||  Hypervisor            |  xen                                          |||
|||  ImageId               |  ami-c5062ba0                                 |||
|||  InstanceId            |  i-017f33143a5b3d2fe                          |||
|||  InstanceType          |  t2.micro                                     |||
|||  KeyName               |  aws_key1                                     |||
|||  LaunchTime            |  2017-10-11T14:08:13.000Z                     |||
|||  PrivateDnsName        |  ip-*********.compute.internal  |||
|||  PrivateIpAddress      |  172.31.46.150                                |||
|||  PublicDnsName         |                                               |||
|||  RootDeviceName        |  /dev/xvda                                    |||
|||  RootDeviceType        |  ebs                                          |||
|||  SourceDestCheck       |  True                                         |||
|||  StateTransitionReason |  User initiated (2017-10-11 14:55:04 GMT)     |||
|||  SubnetId              |  subnet-5f7adb12                              |||
|||  VirtualizationType    |  hvm                                          |||
|||  VpcId                 |  vpc-50efad39                                 |||
||+------------------------+-----------------------------------------------+||
||||                          BlockDeviceMappings                         ||||
|||+-----------------------------------+----------------------------------+|||
||||  DeviceName                       |  /dev/xvda                       ||||
|||+-----------------------------------+----------------------------------+|||
|||||                                 Ebs                                |||||
||||+------------------------------+-------------------------------------+||||
|||||  AttachTime                  |  2017-10-11T14:08:13.000Z           |||||
|||||  DeleteOnTermination         |  True                               |||||
|||||  Status                      |  attached                           |||||
|||||  VolumeId                    |  vol-06d1b8a02b73b7234              |||||
||||+------------------------------+-------------------------------------+||||
||||                              Monitoring                              ||||
|||+-----------------------------+----------------------------------------+|||
||||  State                      |  disabled                              ||||
|||+-----------------------------+----------------------------------------+|||
||||                           NetworkInterfaces                          ||||
|||+---------------------+------------------------------------------------+|||
||||  Description        |                                                ||||
||||  MacAddress         |  0a:8c:8d:fc:82:e8                             ||||
||||  NetworkInterfaceId |  eni-5f7d9f74                                  ||||
||||  OwnerId            |  74*******0                                  ||||
||||  PrivateDnsName     |  ip-**********.compute.internal   ||||
||||  PrivateIpAddress   |  172.31.46.150                                 ||||
||||  SourceDestCheck    |  True                                          ||||
||||  Status             |  in-use                                        ||||
||||  SubnetId           |  subnet-5f7adb12                               ||||
||||  VpcId              |  vpc-50efad39                                  ||||
|||+---------------------+------------------------------------------------+|||
|||||                             Attachment                             |||||
||||+------------------------------+-------------------------------------+||||
|||||  AttachTime                  |  2017-10-11T14:08:13.000Z           |||||
|||||  AttachmentId                |  eni-attach-b62a445d                |||||
|||||  DeleteOnTermination         |  True                               |||||
|||||  DeviceIndex                 |  0                                  |||||
|||||  Status                      |  attached                           |||||
||||+------------------------------+-------------------------------------+||||
|||||                               Groups                               |||||
||||+------------------------------+-------------------------------------+||||
|||||  GroupId                     |  sg-3f2aa357                        |||||
|||||  GroupName                   |  aws_wrk                            |||||
||||+------------------------------+-------------------------------------+||||
|||||                         PrivateIpAddresses                         |||||
||||+-------------------+------------------------------------------------+||||
|||||  Primary          |  True                                          |||||
|||||  PrivateDnsName   |  ip-***********.compute.internal   |||||
|||||  PrivateIpAddress |  172.31.46.150                                 |||||
||||+-------------------+------------------------------------------------+||||
||||                               Placement                              ||||
|||+----------------------------------------+-----------------------------+|||
||||  AvailabilityZone                      |  us-east-2c                 ||||
||||  GroupName                             |                             ||||
||||  Tenancy                               |  default                    ||||
|||+----------------------------------------+-----------------------------+|||
||||                            SecurityGroups                            ||||
|||+-------------------------------+--------------------------------------+|||
||||  GroupId                      |  sg-3f2aa357                         ||||
||||  GroupName                    |  aws_wrk                             ||||
|||+-------------------------------+--------------------------------------+|||
||||                                 State                                ||||
|||+----------------------------+-----------------------------------------+|||
||||  Code                      |  80                                     ||||
||||  Name                      |  stopped                                ||||
|||+----------------------------+-----------------------------------------+|||
||||                              StateReason                             ||||
|||+----------+-----------------------------------------------------------+|||
||||  Code    |  Client.UserInitiatedShutdown                             ||||
||||  Message |  Client.UserInitiatedShutdown: User initiated shutdown    ||||
|||+----------+-----------------------------------------------------------+|||
||||                                 Tags                                 ||||
|||+------------------------------+---------------------------------------+|||
||||  Key                         |  aws_dev                              ||||
||||  Value                       |  u01                                  ||||
|||+------------------------------+---------------------------------------+|||


Viewing all articles
Browse latest Browse all 191

Trending Articles