async waitForNotInUse()

in components/base/packages/custom-domains-cfn-resource/lib/certificate-raw.js [73:116]


  async waitForNotInUse(CertificateArn, acm) {
    const isInUse = async idx => {
      // call describeCertificate return InUseBy.length !== 0
      const result = await acm.describeCertificate({ CertificateArn }).promise();
      logDebug(`waitForNotInUse: idx-${idx}: describeCertificate:  result: ${JSON.stringify(result)}`);
      const { Certificate: certificate } = result;
      const { InUseBy: inUseBy } = certificate;
      return inUseBy.length !== 0;
    };

    // this is a polling affair...
    // call describeCertificate until InUseBy is an empty array
    // worst case scenario it will take 15 mins; alas, the lambda execution is also 15 minutes; race condition?
    // for the first 1 minutes check once every 10 seconds
    for (let idx = 0; idx < 6; ++idx) {
      // 6 times
      if (!(await isInUse(idx))) return;
      await sleep(10000); // every 10 seconds
    }
    // for next 12 minutes check once every 60 seconds
    for (let idx = 6; idx < 6 + 12; ++idx) {
      // 12 times
      if (!(await isInUse(idx))) return;
      await sleep(60000); // every 60 seconds
    }
    // for next 1 minutes check once every 10 seconds
    for (let idx = 6 + 12; idx < 6 + 12 + 6; ++idx) {
      // 6 times
      if (!(await isInUse(idx))) return;
      await sleep(10000); // every 10 seconds
    }
    // for next 1 minutes check once every 1 seconds
    for (let idx = 6 + 12 + 6; idx < 6 + 12 + 6 + 60 - 1; ++idx) {
      // 59 times
      if (!(await isInUse(idx))) return;
      await sleep(1000); // every 1 second
    }
    // try one last time
    if (!(await isInUse(6 + 12 + 6 + 60))) return;
    // by the time got here almost 15 minutes passed (all but a bit less than a second)

    // if got here fail
    fnFail('timeout in waiting for certificate not be in use in preparation for deletion');
  }