SameerMesiah97 opened a new pull request, #61272: URL: https://github.com/apache/airflow/pull/61272
**Description** This PR follows up on PR #60904 by refining cleanup behavior in `EC2CreateInstanceOperator`. Cleanup behavior is **guarded by a flag** and is **opted in by default**. Cleanup is only triggered for post-start EC2 instance failures (including `WaiterError`), ensuring termination is attempted only when an instance was successfully created and **avoiding interception of non-AWS exceptions**. **Rationale** Restricting cleanup to post-creation EC2 instance failures prevents unintended termination in unrelated failure paths while still addressing orphaned instances created during execution, and aligns EC2 cleanup semantics with recent changes to other AWS resource creation operators proposed in PRs #61145, #61051, and #61010 . **Tests** Existing tests continue to validate cleanup behavior. The new `terminate_instance_on_failure` flag is now explicitly set to `True` in applicable tests for explicitness. Documentation The docstring for `EC2CreateInstanceOperator` has been updated with a brief description of the new flag term. **Backwards Compatibility** A new flag, `terminate_instance_on_failure`, has been added to `EC2CreateInstanceOperator` with a default value of `True`. Best-effort cleanup will now be attempted if a post-creation failure (including `WaiterError`) occurs after the EC2 instance has been successfully created. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
