AWS Lambda实例的唯一标识符是什么?

huangapple go评论138阅读模式
英文:

Unique id of aws-lambda instance?

问题

因为Lambda函数是无状态的,多个实例可以同时运行,所以基于时间戳生成ID可能不是一个好主意。我目前正在使用UUIDv1。我知道在相同时间戳下生成相同ID的几乎不可能。对于我的应用来说,这已经足够唯一。出于好奇,我在思考在AWS Lambda上生成真正数学唯一ID的方法。

UUID v1使用节点来区分在相同时间戳下生成的ID。随机数字或MAC地址(对于虚拟实例来说不是一个好主意)被用来创建节点ID。

如果我有一个针对我的活动Lambda实例的唯一ID,我就能够生成真正唯一的ID。在上下文对象中有一个awsRequestId,但它似乎只是另一个基于时间戳的UUID。

也许你们有更多的想法呢?

英文:

Because lambdas are stateless and multiple instances can run at the same time it might be a bad idea to generate ids based on timestamps. I am currently using UUIDv1. I know the chance of generating the same IDs with the same timestamp already literally impossible. It's also enough unique enough for my application. Out of curiosity I'm thinking of ways to generate truly mathematically unique ids on aws lambda.

UUID v1 uses a node to distinct ids generated with the same timestamp. Random numbers or MAC-Adresses (bad idea for virtual instances) are used to create node ids.

If I had a unique id for my active lambda instance I would be able to generate truly unique ids. There is a awsRequestId inside the context object but it just seems like another timestamp based UUID.

Maybe you guys have more ideas?

答案1

得分: 1

AWS lambda:

System.getenv("AWS_LAMBDA_LOG_STREAM_NAME").replaceFirst(".*?(?=\\w+$)", EMPTY)

定义的运行时环境变量

AWS EC2:

httpGet http://169.254.169.254/latest/meta-data/instance-id

实例元数据和用户数据

AWS ECS:

httpGet http://localhost:51678/v1/metadata

如何从ECS容器内部获取任务ID?

英文:

AWS lambda:

System.getenv("AWS_LAMBDA_LOG_STREAM_NAME").replaceFirst(".*?(?=\\w+$)", EMPTY)

Defined runtime environment variables

AWS EC2:

httpGet http://169.254.169.254/latest/meta-data/instance-id

Instance metadata and user data

AWS ECS:

httpGet http://localhost:51678/v1/metadata

How to get Task ID from within ECS container?

答案2

得分: 0

在子网内唯一

String executableId = ManagementFactory.getRuntimeMXBean().getName();

英文:

Unique within subnet

String executableId = ManagementFactory.getRuntimeMXBean().getName();

huangapple
  • 本文由 发表于 2020年4月10日 21:07:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/61140931.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定