<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_ec2_client(region_name=None, aws_access_key_id=None, aws_secret_access_key=None):
 """Gets an EC2 client :return: boto3.client object :raises: AWSAPIError """

    log = logging.getLogger(mod_logger + '.get_ec2_client')
    # Connect to EC2 API
    try:
        client = boto3.client('ec2', region_name=region_name, aws_access_key_id=aws_access_key_id,
                              aws_secret_access_key=aws_secret_access_key)
    except ClientError:
        _, ex, trace = sys.exc_info()
        msg = 'There was a problem connecting to EC2, please check AWS CLI and boto configuration, ensure ' \
              'credentials and region are set appropriately.\n{e}'.format(e=str(ex))
        log.error(msg)
        raise AWSAPIError, msg, trace
    else:
        log.debug('Successfully created an EC2 client')
        return client