in github-runner-ami/packer/files/runner-supervisor.py [0:0]
def main(repo, output_folder, user):
    global INSTANCE_ID
    # Notify the ASG LifeCycle hook that we are now In Service and ready to
    # process requests/safe to be shut down
    # Fetch current instance ID from where cloutinit writes it to
    if not INSTANCE_ID:
        with open('/var/lib/cloud/data/instance-id') as fh:
            INSTANCE_ID = fh.readline().strip()
    log.info("Starting on %s...", INSTANCE_ID)
    output_folder = os.path.expanduser(output_folder)
    short_time = datetime.timedelta(microseconds=1)
    dynamodb = boto3.resource('dynamodb')
    client = DynamoDBLockClient(
        dynamodb,
        table_name='GitHubRunnerLocks',
        expiry_period=datetime.timedelta(0, 300),
        heartbeat_period=datetime.timedelta(seconds=10),
    )
    # Just keep trying until we get some credentials.
    while True:
        # Have each runner try to get a credential in a random order.
        possibles = get_possible_credentials(repo)
        random.shuffle(possibles)
        log.info("Trying to get a set of credentials in this order: %r", possibles)
        notify = get_sd_notify_func()
        for index in possibles:
            try:
                lock = client.acquire_lock(
                    f'{repo}/{index}',
                    retry_period=short_time,
                    retry_timeout=short_time,
                    raise_context_exception=True,
                )
            except DynamoDBLockError as e:
                log.info("Could not lock %s (%s)", index, e)
                continue
            with lock:
                log.info("Obtained lock on %s", index)
                write_credentials_to_files(repo, index, output_folder, user)
                merge_in_settings(repo, output_folder)
                notify(f"STATUS=Obtained lock on {index}")
                if get_lifecycle_state() == "Pending:Wait":
                    complete_asg_lifecycle_hook()
                notify("READY=1")
                log.info("Watching for Runner.Worker processes")
                ProcessWatcher().run()
            client.close()
            exit()