是否可以找到EC2实例是否与Auto Scaling Group相关联?
答案 0 :(得分:3)
您可以使用describe-auto-scaling-instances函数来检查实例附加到的自动伸缩组。
例如,对于实例ID i-4ba0837f
,您可以运行以下命令
aws autoscaling describe-auto-scaling-instances --instance-ids i-4ba0837f
如果附加到自动缩放组,示例响应如下
{
"AutoScalingInstances": [
{
"ProtectedFromScaleIn": false,
"AvailabilityZone": "us-west-2c",
"InstanceId": "i-4ba0837f",
"AutoScalingGroupName": "my-auto-scaling-group",
"HealthStatus": "HEALTHY",
"LifecycleState": "InService",
"LaunchConfigurationName": "my-launch-config"
}
]
}
但是,如果未附加任何内容,则该列表将为空。
{
"AutoScalingInstances": []
}
如果未返回任何结果,则该实例不属于自动伸缩组。
这也将在SDK中提供:
答案 1 :(得分:2)
您可以使用以下aws cli命令:
aws autoscaling describe-auto-scaling-instances --instance-ids i-exampleid
如果该实例属于自动伸缩组的一部分,则结果将为您提供详细信息。
https://docs.aws.amazon.com/cli/latest/reference/autoscaling/describe-auto-scaling-instances.html
答案 2 :(得分:1)
您可以使用describe-auto-scaling-instances
aws autoscaling describe-auto-scaling-instances --instance-ids your-instance-id
如果存在,它将打印类似这样的内容
{
"AutoScalingInstances": [
{
"InstanceId": "some-instance-id",
"InstanceType": "m4.large",
"AutoScalingGroupName": "awseb-some-name",
"AvailabilityZone": "eu-west-1c",
"LifecycleState": "InService",
"HealthStatus": "HEALTHY",
"LaunchTemplate": {
"LaunchTemplateId": "lt-04a2fffdesa",
"LaunchTemplateName": "AWSEBEC2LaunchTemplate_foobar",
"Version": "2"
},
"ProtectedFromScaleIn": false
}
]
}
如果不是
{
"AutoScalingInstances": []
}
答案 3 :(得分:0)
您还可以查看实例标签以了解它是否属于ASG。 ASG中的EC2始终带有aws:autoscaling:groupName
标签。