- Newest
- Most votes
- Most comments
To delay the termination of the new instance during an Elastic Beanstalk immutable deployment, you can configure instance retention using EC2 Auto Scaling's instance lifecycle policy feature. This will allow you to keep the instance available for troubleshooting even when the deployment fails.
Here's how to set this up:
Configure Instance Lifecycle Policy:
You'll need to modify the Auto Scaling group that Elastic Beanstalk creates during the immutable deployment. Set up an instance lifecycle policy with retention triggers that will keep instances when termination lifecycle hooks are abandoned or timeout.
- Add a termination lifecycle hook to the Auto Scaling group with:
- Lifecycle transition: "autoscaling:EC2_INSTANCE_TERMINATING"
- Default result: "ABANDON"
- A heartbeat timeout (e.g., 300 seconds)
- Configure the instance lifecycle policy to retain instances when the termination hook is abandoned. This is done by setting the retention trigger to "TerminateHookAbandon" with an action of "retain."
When the deployment fails and AWS attempts to terminate the new instance, the lifecycle hook will trigger. If it times out or is abandoned, the instance will be retained in a "retained" state rather than being immediately terminated. This gives you time to SSH into the instance and investigate the deployment failure.
You can later manually terminate the instance once you've completed your troubleshooting. Note that this feature is available in specific regions including US East (N. Virginia), US West (Oregon), Europe (Ireland), and Asia Pacific (Singapore).
Sources
EC2 Auto Scaling introduces instance lifecycle policy - AWS
Configure instance retention - Amazon EC2 Auto Scaling
