async function getAuth(credentials, getCredentials) {
  let creds = credentials
  /* Use custom creds function */
  if (!Object.keys(creds).length && getCredentials) {
    try {
      creds = await getCredentials()
    } catch (err) {
      throw new Error(err)
    }
  }

  const auth = {
    // Support amplify and raw client auth params
    accessKeyId: creds.accessKeyId || creds.AccessKeyId,
    secretAccessKey: creds.secretAccessKey || creds.SecretKey,
    sessionToken: creds.sessionToken || creds.SessionToken,
    retries: 5,
  }
  return auth
}
/

  let aws, data
  const payload = {
    body: JSON.stringify(eventsRequest),
  }
  
  if (process.browser) {
    aws = new AwsClient(auth)
    data = await aws.fetch(endpointUrl, payload).then((d) => d.json())
  } else {

    aws = new AWS.PinpointClient({
      credentials: auth,
      region: pinpointRegion,
    })

    const command = new AWS.PutEventsCommand({
      ApplicationId: pinpointAppId,
      EventsRequest: eventsRequest,
    })
    data = await aws.send(command)
  }

  if (data && data.Results) {
    // Process api responses
    const responses = Object.keys(data.Results).map(
      (eventId) => data.Results[eventId]
    )
    /* Message: "Session duration in milliseconds must be equal to the difference of start and stop timestamp"
    StatusCode: 400
    Session: {Id: "c024eae8-4978-4d2b-898d-31b89ddd62d3", StartTimestamp: "2021-05-25T06:09:30.632Z", Duration: 20008, StopTimestamp: "2021-05-25T06:09:50.641Z"}
    // new Date('2021-05-25T06:09:50.641Z').getTime() - new Date('2021-05-25T06:09:30.632Z').getTime() === 20009