如何在 python 中获取 azure 函数的唯一实例 ID?

How to get unique instance id of azure function in python?

我正在尝试通过 Azure 函数(Python 环境)在数据库中保存一些信息(多行)。

为此,我正在寻找唯一标识符 corr。每个 运行 的 azure 函数。

我在几个地方遇到过 GUID 这个词,但是我找不到任何关于如何在 Azure Function Python 环境中使用这个函数或属性的文档。

如有任何帮助,我们将不胜感激。

GUID技术不是Python Azure Function独有的,它是一种常用的唯一标识符,是根据当前时间和计算机生成的,你可以在python中这样生成它:

import uuid

print(uuid.uuid4())

在 azure 函数中,使用以下代码获取它:

import logging

import azure.functions as func


def main(req: func.HttpRequest,context: func.Context) -> func.HttpResponse:
    logging.info(context.invocation_id)
    return func.HttpResponse(
            "This is the GUID:" + context.invocation_id,
            status_code=200
    )

告诉我这是否对您有帮助。