refactored code to reuse getting of instance from AWS-EC2