Re-factor code for limiting AWS instances to reduce duplication.