refactor getExistEc2Instances method to use flatMap.