def ec2_client(region, zone, access_key_id,
               secret_access_key, session_token=None, validate_region=True):
    # Set a retry option in Botocore to BOTO_NUM_RETRIES:
    # ``metadata_service_num_attempts``:
    # Request for retry attempts by Boto to
    # retrieve data from Metadata Service used to retrieve
    # credentials for IAM roles on EC2 instances.
    # Exponential backoff and retry for ``RequestLimitExceeded``
    # errors is already set in botocore.
    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)
:raises: :exc:`rospkg.ResourceNotFound` if *resource_name* cannot be found.
dataset/ETHPy150Open ClusterHQ/flocker/flocker/node/agents/ebs.py/ec2_client--crossover with--dataset/ETHPy150Open ros-infrastructure/rosdep/src/rosdep2/loader.py/RosdepLoader.get_rosdeps