AWS EC2 Instance Lifecycle


  • An instance is a virtual server in the AWS cloud.You launch an instance from an Amazon Machine Image (AMI).
  • AMI provides the operating system, application server, and applications for your instance.
  • When an instance is launched, it receives a public DNS name that can be used to contact the instance from the Internet. Instance also receives a private DNS name that other instances within the same Amazon EC2 network can use to contact the instance

Instance Lifecycle

EC2 Instance Lifecycle

  • Pending
    • When the instance is first launched is enters into the pending state
  • Running
    • After the instance is launched, it enters into the running state
    • Charges are incurred for every hour or partial hour the instance is running even if it is idle
  • Start & Stop (EBS-backed instances only)
    • Only and EBS-backed instance can be stopped and started. Instance store-bakced instance cannot be stopped and started
    • An instance can stopped & started in case the instance fails a status check or is not running as expected
    • Stop
      • After the instance is stopped, it enters in stopping state and then to stopped state.
      • Charges are only incurred for the EBS storage and not for the instance hourly charge or data transfer.
      • While the instance is stopped, you can treat its root volume like any other volume, and modify it for e.g. repair file system problems or update software or change the instance type, user data, EBS otpmization attributes etc
      • Volume can be detached from the stopped instance, and attached to a running instance, modified, detached from the running instance, and then reattached to the stopped instance. It should be reattached using the storage device name that’s specified as the root device in the block device mapping for the instance.
    • Start
      • When the instance is started, it enters into pending state and then into running
      • An instance when stopped and started is launched on a new host
      • Any data on an instance store volume (not root volume) would be lost while data on the EBS volume persists
    • EC2 instance retains its private IP address as well as the Elastic IP address. However, the public IP address, if assigned instead of the Elastic IP address, would be released
    • Charges for full hour are incurred for every transition from stopped to running, even if the transition is within the same hour for e.g. if you stop and start your instances 2 times in an hour, you would be charged for 3 full hours, one for the start and then for the 2 transitions as if you had 3 instances running during that hour
  • Instance reboot
    • Both EBS-backed and Instance store-backed instances can be rebooted
    • An instance retains it public DNS, public and private IP address during the reboot
    • Data on the EBS and Instance store volume is also retained
    • Amazon recommends to use Amazon EC2 to reboot the instance instead of running the operating system reboot command from your instance as it performs a hard reboot if the instance does not cleanly shutdown within four minutes also creates an API record in CloudTrail, if enabled.
  • Instance retirement
    • An instance is scheduled to be retired when AWS detects irreparable failure of the underlying hardware hosting the instance.
    • When an instance reaches its scheduled retirement date, it is stopped or terminated by AWS.
    • If the instance root device is an Amazon EBS volume, the instance is stopped, and can be started again at any time.
    • If the instance root device is an instance store volume, the instance is terminated, and cannot be used again.
  • Instance Termination
    • An instance can be terminated, and it enters into the shutting-down and then the terminated state
    • After an instance is terminated, it can’t be connected and no charges are incurred
    • Instance Shutdown behaviour
      • EBS-backed instance supports InstanceInitiatedShutdownBehavior attribute which determines whether the instance would be stopped or terminated when a shutdown command is initiated from the instance itself for e.g. shutdown, halt or poweroff command in linux.
      • Default behaviour for the the instance to be stopped.
      • A shutdown command for an Instance store-backed instance will always terminate the instance
    • Termination protection
      • Termination protection (DisableApiTermination attribute) can be enabled on the instance to prevent it from being accidently terminated
      • DisableApiTerminationfrom the Console, CLI or API.
      • Instance can be terminated through Amazon EC2 CLI.
      • Termination protection does not work for instances when
        • part of an Autoscaling group
        • launched as Spot instances
        • terminating an instance by initiating shutdown from the instance
    • Data persistence
      • EBS volume have a DeleteOnTermination attribute which determines whether the volumes would be persisted or deleted when an instance they are associated with are terminated
      • Data on Instance store volume data does not persist
      • Data on EBS root volumes, have the DeleteOnTermination flag set to true, would be deleted by default
      • Additional EBS volumes attached have the DeleteOnTermination flag set to false are not deleted but just dettached from the instance

Screen Shot 2016-04-30 at 7.16.00 AM.png

AWS Certification Exam Practice Questions

  • Questions are collected from Internet and the answers are marked as per my knowledge and understanding (which might differ with yours).
  • AWS services are updated everyday and both the answers and questions might be outdated soon, so research accordingly.
  • AWS exam questions are not updated to keep up the pace with AWS updates, so even if the underlying feature has changed the question might not be updated
  • Open to further feedback, discussion and correction.
  1. What does Amazon EC2 provide?
    1. Virtual servers in the Cloud
    2. A platform to run code (Java, PHP, Python), paying on an hourly basis.
    3. Computer Clusters in the Cloud.
    4. Physical servers, remotely managed by the customer.
  2. A user has enabled termination protection on an EC2 instance. The user has also set Instance initiated shutdown behavior to terminate. When the user shuts down the instance from the OS, what will happen?
    1. The OS will shutdown but the instance will not be terminated due to protection
    2. It will terminate the instance
    3. It will not allow the user to shutdown the instance from the OS
    4. It is not possible to set the termination protection when an Instance initiated shutdown is set to Terminate
  3. A user has launched an EC2 instance and deployed a production application in it. The user wants to prohibit any mistakes from the production team to avoid accidental termination. How can the user achieve this?
    1. The user can the set DisableApiTermination attribute to avoid accidental termination
    2. It is not possible to avoid accidental termination
    3. The user can set the Deletion termination flag to avoid accidental termination
    4. The user can set the InstanceInitiatedShutdownBehavior flag to avoid accidental termination
  4. You have been doing a lot of testing of your VPC Network by deliberately failing EC2 instances to test whether instances are failing over properly. Your customer who will be paying the AWS bill for all this asks you if he being charged for all these instances. You try to explain to him how the billing works on EC2 instances to the best of your knowledge. What would be an appropriate response to give to the customer in regards to this?
    1. Billing commences when Amazon EC2 AMI instance is completely up and billing ends as soon as the instance starts to shutdown.
    2. Billing commences when Amazon EC2 initiates the boot sequence of an AMI instance and billing ends when the instance shuts down.
    3. Billing only commences only after 1 hour of uptime and billing ends when the instance terminates.
    4. Billing commences when Amazon EC2 initiates the boot sequence of an AMI instance and billing ends as soon as the instance starts to shutdown.