获取云功能实例的唯一标识符 [英] Get unique identifier of a Cloud Function instance

查看:58
本文介绍了获取云功能实例的唯一标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以在函数内部访问Goodle Cloud Function当前实例的唯一标识符?当我检查功能日志时,我可以看到每个实例都有一个标识符.我想在函数运行时访问该标识符.我打算在每次调用函数后在其中一个存储分区中创建包含某些内容的唯一文件夹.除了是唯一的文件夹之外,我还可以使用创建它的功能轻松地映射这些文件夹.

Is there any way to access a unique identifier of the Goodle Cloud Function's current instance inside the function? When I check the function logs I can see there is an identifier to each instance. I would like to access this identifier inside the function while it is running. My intention to create unique folders with some content in one of my storage bucket after each invoked function. Besides being unique folders it would be also great that I can map those easyly with the function which created it.

推荐答案

我认为您正在观察的不是实例ID",而是更类似于事件提供者分配的事件ID.传递给每个后台函数调用的第二个参数是一个包含事件ID的上下文对象.此ID的目的是帮助您编写幂等函数.它们并不是真正旨在具有全球唯一性.

I think what you're observing is not an "instance ID" and more like the event ID assigned by the event provider. The second argument passed to every background function invocation is a context object that contains the event ID. The purpose of this ID is to help you write functions that are idempotent. They are not really intended to be universally unique.

我建议您仅使用适用于您所使用语言的任何标准库来生成自己的UUID.两个UUID发生碰撞的可能性天文上很小,并且可以确保您为此值找到一个表格".

I suggest that you just generate your own UUID using whatever standard library is available for the language you're using. The chance of two UUIDs colliding is astronomically small, and you are guaranteed a "form" for that value.

这篇关于获取云功能实例的唯一标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆