code: def _maybe_create_resources(logging_task: Task = None):
    def log(*args):
      if logging_task:
        logging_task.log(*args)
      else:
        util.log(*args)
    def should_create_resources():
      prefix = u.get_prefix()
      if u.get_keypair_name() not in u.get_keypair_dict():
        log(f"Missing {u.get_keypair_name()} keypair, creating resources")
        return True
      vpcs = u.get_vpc_dict()
      if prefix not in vpcs:
        log(f"Missing {prefix} vpc, creating resources")
        return True
      vpc = vpcs[prefix]
      gateways = u.get_gateway_dict(vpc)
      if prefix not in gateways:
        log(f"Missing {prefix} gateway, creating resources")
        return True
      return False
    try:
      if os.path.exists(AWS_LOCK_FN):
        pid, ts, lock_taskname = open(AWS_LOCK_FN).read().split('-')
        ts = int(ts)
        log(f"waiting for aws resource creation, another resource initiation was "
            f"initiated {int(time.time()-ts)} seconds ago by "
            f"{lock_taskname}, delete lock file "
            f"{AWS_LOCK_FN} if this is an error")
        while True:
          if os.path.exists(AWS_LOCK_FN):
            log(f"waiting for lock file {AWS_LOCK_FN} to get deleted "
                f"initiated {int(time.time()-ts)} seconds ago by ")
            time.sleep(2)
            continue
          else:
            break
        return
      with open(AWS_LOCK_FN, 'w') as f:
        f.write(
          f'{os.getpid()}-{int(time.time())}-{logging_task.name if logging_task else ""}')
      if not should_create_resources():
        util.log("Resources already created, no-op")
        os.remove(AWS_LOCK_FN)
        return
      create_lib.create_resources()
    finally:
      if os.path.exists(AWS_LOCK_FN):
        os.remove(AWS_LOCK_FN)