‹ All DOP-C02 questions

DOP-C02 Practice Question 15: ASG Termination Lifecycle Hook

AWS Certified DevOps Engineer – Professional (DOP-C02) · Test 2 · question 5 of 10

Resilient Cloud Solutionsmedium

Instances in an Amazon EC2 Auto Scaling group process jobs from a queue and buffer application logs locally. When a target tracking policy scales in, instances are terminated before they finish their current job and before their logs are uploaded to Amazon S3, so the data is lost. A drain script on the instance handles both tasks and takes up to 10 minutes. The team wants the script to run on every instance that scale-in selects, termination to proceed as soon as the script finishes, and the scaling policy to stay the only thing that decides when to scale in.

What should the team do?

Select one answer
Show answer and explanation

Answer:

  • B. Add a lifecycle hook for autoscaling:EC2_INSTANCE_TERMINATING with a heartbeat timeout longer than 10 minutes, use an EventBridge rule for the hook's event to run the drain script, and have the script call complete-lifecycle-action with CONTINUE when it finishes

A termination lifecycle hook pauses an instance in a wait state after scale-in selects it and before it is terminated. Amazon EC2 Auto Scaling sends an event to Amazon EventBridge, and a rule can start the custom action. The docs give this exact example: invoke a Lambda function, or connect to the instance, "to download logs or other data before the instance is fully terminated". The heartbeat timeout (one hour by default) caps the wait. Setting it above the script's 10 minutes leaves room to finish, and calling complete-lifecycle-action ends the wait early so termination proceeds as soon as the work is done. The scaling policy still picks which instances go and when. Note that termination hooks are best-effort: if the hook times out or is abandoned, the instance is terminated anyway.

Option A controls something else. Deregistration delay lets in-flight *load balancer* requests drain from a target. It does not run a script, it does nothing for queue workers pulling jobs, and it does not make Auto Scaling wait for logs to be uploaded.

Option C relies on the operating system's shutdown sequence, which gives no guaranteed 10-minute window. The instance is powered off on EC2's schedule, not when the script finishes, so a long drain can be cut short. The launch hook only puts the script in place. Nothing gives it time to run at termination.

Option D takes the decision away from the scaling policy. Scale-in protection stops Auto Scaling from terminating protected instances during scale-in, so the group would stop shrinking unless each instance chose to terminate itself. That breaks the requirement that the policy alone decides when to scale in.

Reference: Amazon EC2 Auto Scaling lifecycle hooks

Practice Test 2 ›

Study guides for DOP-C02

AWS Service Control Policies Explained: SCPs and DenialsAWS service control policies explained: how SCPs cap permissions, why admins still get access denied, inheritance, deny vs allow lists and the exam traps.
How AI Is Changing Software Jobs: Where to PrepareHow AI is changing software jobs: what history shows, the evidence on junior developers, what Klarna learned, new AI roles and five domains to prepare for.
How AWS Certification Exams Work: Scoring and RenewalHow AWS certification exams work: levels, booking, question types, unscored questions, scaled scores, pass marks, validity and how recertification works.
What Is Amazon RDS? Multi-AZ, Read Replicas and BackupsWhat is Amazon RDS? Engines, Multi-AZ, read replicas, backups, RDS Proxy, Aurora and pricing explained, with the traps that AWS exams set around each one.
Best DevOps certification: AWS, Azure, Google or CKAThe best DevOps certification for your stack: AWS DOP-C02, Azure AZ-400, Google Cloud DevOps Engineer and CKA compared on cost, level and prerequisites.
What Is AWS Lambda? Triggers, Concurrency and Cold StartsWhat is AWS Lambda? How functions run, cold starts, triggers vs event source mappings, concurrency, layers, aliases, pricing and the exam traps.
AWS CloudOps Engineer Associate (SOA-C03) exam guideAWS Certified CloudOps Engineer – Associate (SOA-C03) replaced SysOps Administrator. Format, cost, the five domains, what changed and how to prepare.
Which AWS certification should you get? 2026 roadmapWhich AWS certification to get first, by role and experience, with each exam's status in October 2026, what is changing, and prices in USD and INR.
What Is Amazon EC2? Instances, AMIs, EBS and Auto ScalingAmazon EC2 explained: instances, AMIs, instance types, security groups, EBS, Auto Scaling groups and pricing options, with the traps AWS exams set.
SQS vs SNS vs EventBridge on AWSWhen to use an SQS queue, an SNS topic or an EventBridge bus, plus fan-out, FIFO ordering, visibility timeouts and dead-letter queues for AWS exams.