def ec2_client(region, zone, access_key_id, secret_access_key, session_token=None, validate_region=True):
 connection = boto3.session.Session(aws_access_key_id=access_key_id, aws_secret_access_key=secret_access_key, aws_session_token=session_token)
 connection._session.set_config_variable('metadata_service_num_attempts', BOTO_NUM_RETRIES)
 ec2_resource = connection.resource('ec2', region_name=region)
 if validate_region:
  try:
   zones = ec2_resource.meta.client.describe_availability_zones()
  except EndpointConnectionError:
   raise InvalidRegionError(region)
  available_zones = [available_zone['ZoneName'] for available_zone in zones['AvailabilityZones']]
  if (zone not in available_zones):
   raise InvalidZoneError(zone, available_zones)
 return _EC2(zone=zone, connection=ec2_resource)

def ec2_client ( region , zone , access_key_id , secret_access_key , session_token = None , validate_region = True ) : connection = boto3 . session . Session ( aws_access_key_id = access_key_id , aws_secret_access_key = secret_access_key , aws_session_token = session_token ) connection . _session . set_config_variable ( 'metadata_service_num_attempts' , BOTO_NUM_RETRIES ) ec2_resource = connection . resource ( 'ec2' , region_name = region ) if validate_region : try : zones = ec2_resource . meta . client . describe_availability_zones ( ) except EndpointConnectionError : raise InvalidRegionError ( region ) available_zones = [ available_zone [ 'ZoneName' ] for available_zone in zones [ 'AvailabilityZones' ] ] if ( zone not in available_zones ) : raise InvalidZoneError ( zone , available_zones ) return _EC2 ( zone = zone , connection = ec2_resource )
establish connection to ec2 client .