def getInstance(region): ec2 = getResourceEc2(region) list = [] try: for instances in ec2.instances.all(): Instances = Instance.instance( instances.image.name, instances.platform, instances.instance_type, instances.public_dns_name, instances.state.get("Name"), instances.private_ip_address, instances.tags[0].get("Value"), instances.id, instances.key_name) list.append(Instances) return jsonify([ob.__dict__ for ob in list]) except ClientError as e: data = {"status": "fail", "message": "region not available"} response = app.response_class(status=404, response=json.dumps(data), mimetype='application/json') return response