Terminating our EC2 instance

As with most Hello World exercises, once the helloworld message is displayed, the goal is reached. It is now time to think about shutting down our server. Since we only pay for what we consume in AWS, freeing up unnecessary resources such as this server is a good strategy for making AWS very cost effective.

We can do a clean shutdown of the Hello World service using the stop command. We can then exit the virtual server and terminate our instance, as follows:

[ec2-user@ip-172-31-22-52 ~]$ sudo stop helloworld helloworld stop/waiting [ec2-user@ip-172-31-22-52 ~]$ ec2-metadata --instance-id instance-id: i-057e8deb1a4c3f35d [ec2-user@ip-172-31-22-52 ~]$ exit logout $ aws ec2 terminate-instances --instance-ids i-057e8deb1a4c3f35d ...

Get Effective DevOps with AWS - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.