向使用AWS中的自动缩放组创建的ec2实例提供增量名称的方法 [英] Method to provide incremental name to ec2 instances created using auto scaling group in aws

查看:111
本文介绍了向使用AWS中的自动缩放组创建的ec2实例提供增量名称的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在aws中配置一个自动伸缩组以创建ec2服务器.当自动缩放组(例如server-01,server-02等)创建新实例时,我想在名称标签中添加增量值.

I am configuring an auto scaling group in aws to create ec2 servers. I want to add incremental value to the name tag when a new instance is created by the auto scaling group (Example server-01, server-02 etc.)

是否有任何方法可以将名称标签添加到使用上述自动缩放组创建的资源中.

Is there any method to add name tag to resource created using auto scaling group as mentioned above.

推荐答案

您可以使用Lambda来执行此操作,以响应 DescribeAutoScalingGroups 来查找实例.属于ASG,并更新那些没有该标签的广告.

You could do this with a Lambda, responding to a life-cycle event. The Lambda would call DescribeAutoScalingGroups to find the instance(s) belonging to the ASG, and update those that don't have the tag.

如果您只是想将所有实例编号为1..N,那么我建议您侦听关闭事件和启动事件,并根据其开始时间戳重新标记所有实例.

If you simply want to have all of your instances numbered 1..N, then I would recommend listening to shutdown events as well as startup events, and retagging all instances based on their starting timestamp.

如果要将序列号应用于每个新实例,则需要将当前值存储在某个地方,例如DynamoDB.您还需要注意并发执行,并确保每个序列号只能使用一次,也只能使用一次.您可以通过存储序列号和实例ID之间的关联来做到这一点.

If you want to apply sequential numbers to every new instance, you'll need to store the current value somewhere, such as DynamoDB. You'll also need to beware of concurrent executions, and make sure that you use each sequence number once and only once. You can do this by storing an association between sequence number and instance ID.

但是为什么要这么做呢?

But why would you want to do this?

这篇关于向使用AWS中的自动缩放组创建的ec2实例提供增量名称的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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