Description:

Amazon Elastic Compute Cloud (Amazon EC2) provides secure and resizable computing capacity in the AWS Cloud. Using Amazon EC2 eliminates the need to invest in hardware upfront, so you can develop and deploy applications faster.

 

Rationale: 

If you decide that you no longer need an instance, you can terminate it. As soon as the state of an instance changes to shutting down or terminated, we stop charging for that instance. 

Impact:

When you stop the EC2 instance, AWS stops usage charges for the machine But the attached EBS volume (Root) is not deleted and it is still charged in the background, If the EC2 instance is terminated, Then only volume will get automatically deleted, You can changes/do setting in EC2 volume settings delete on Termination checkbox.





Default value :

By default, The EC2 instance is Running

Pre-requisites

We Created EC2 instances with IAM  roles and policies 



Remediation:

Test plan

01:Sign into the AWS Management Console.

02:open  to EC2 dashboard at https://console.aws.amazon.com/ec2/.

03:In the left navigation panel, under the INSTANCES section, choose Instances.

04:Select the  instance id 


05:Check the Instance Status 




Using AWS CLI:

To check the status of the instance 

aws ec2 describe-instance-status --instance-id <value>



implementation step:

Step01:login into the AWS Management Console.

Step 02:Navigate to EC2 dashboard at https://console.aws.amazon.com/ec2/.

Step 03:In the left navigation panel, under the INSTANCES section

Step 04:Select the Stopped EC2 instance that you want to change.

Step 05: Select Instance State  

Step 06: click start to the instance.

OR

Step 07:  Repeat the steps 1 to 5


Step 08: Click on Terminate instances.


Step 09: It will ask you to confirm terminate it click on terminate.


Using AWS CLI:

To terminate the instance 

aws ec2 terminate-instances --instance-ids <value>

To start the instance 

aws ec2 start-instances
  --region <region-name>
  --instance-ids <instance-id>

Back out plan :

 01:Sign into the AWS Management Console.

02:open to EC2 dashboard at https://console.aws.amazon.com/ec2/.

03:In the left navigation panel, under the INSTANCES section, choose Instances.

04: Select the running instance id 

05: Instance state, choose select Stop



Using AWS CLI:

aws ec2 stop-instances --instance-ids <value>


Reference:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#termination-overview 

describe-instances — AWS CLI 1.22.76 Command Reference 

stop-instances — AWS CLI 1.22.75 Command Reference 

ec2-stopped-instance - Amazon Config 

stop-instances — AWS CLI 2.5.0 Command Reference