Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services 有没有办法确定EC2实例是否与自动缩放组关联_Amazon Web Services_Amazon Ec2 - Fatal编程技术网

Amazon web services 有没有办法确定EC2实例是否与自动缩放组关联

Amazon web services 有没有办法确定EC2实例是否与自动缩放组关联,amazon-web-services,amazon-ec2,Amazon Web Services,Amazon Ec2,是否有办法确定EC2实例是否与自动缩放组关联?您可以使用该功能检查实例连接到哪个自动缩放组 因此,例如,对于实例idi-4ba0837f,您可以运行以下命令 aws autoscaling describe-auto-scaling-instances --instance-ids i-4ba0837f 下面是附加到自动缩放组的响应示例 { "AutoScalingInstances": [ { "Protected

是否有办法确定EC2实例是否与自动缩放组关联?

您可以使用该功能检查实例连接到哪个自动缩放组

因此,例如,对于实例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中提供:

您可以使用

如果存在,它将打印类似的内容

{
  "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": []
}

您可以使用以下aws cli命令:

aws autoscaling describe-auto-scaling-instances --instance-ids i-exampleid 
如果实例是自动缩放组的一部分,结果将为您提供详细信息


您还可以查看实例标记以确定它是否属于ASG。ASG中的EC2将始终具有
aws:autoscaling:groupName
标记

aws autoscaling describe-auto-scaling-instances --instance-ids i-exampleid