There is a delay between when ec2 reports the instances as terminated and when the security group is considered empty and can be deleted. Without this sleep the ec2-delete-group command intermittently fails. Yet another example of why this script sucks and we need to replace it with something in python or go that uses the ec2 api directly and can do proper error handling.