What is likely causing this issue?
The two affected instances failed to fetch the new deployment.
A failed AfterInstall lifecycle event hook caused the CodeDeploy agent to roll back to the previous version on the affected instances.
The CodeDeploy agent was not installed in two affected instances.
EC2 Auto Scaling launched two new instances while the new deployment had not yet finished, causing the previous version to be deployed on the affected instances.
Explanations:
The issue is not related to the instances failing to fetch the new deployment, as the overall deployment completed successfully.
A failed AfterInstall lifecycle event hook would cause a rollback, but the issue described does not indicate a failure during the lifecycle hook that would result in rollback on only certain instances.
If the CodeDeploy agent was not installed, the deployment would fail altogether on those instances, not just partially deploy the old revision.
EC2 Auto Scaling could have launched new instances during the deployment, which may have resulted in the previous revision being deployed on those newly launched instances before the deployment was complete.