英文:
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
英文:
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
答案2
得分: 0
在子网内唯一
String executableId = ManagementFactory.getRuntimeMXBean().getName();
英文:
Unique within subnet
String executableId = ManagementFactory.getRuntimeMXBean().getName();
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论