未使用的AWS预留实例中的问题 [英] Issue in Unused AWS Reserved Instances

查看:356
本文介绍了未使用的AWS预留实例中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在检查未使用的保留实例时,我使用Python脚本从Github中检索了名为

In checking unutilized reserved instances, I retrieve those using python script from Github called ec2-check-reserved-instances. It contains:

            running_instances = {}
            for reservation in reservations:
            for instance in reservation.instances:
            if instance.state != "running":
                  sys.stderr.write("Disqualifying instance %s: not running\n" % ( instance.id ) )
            elif instance.spot_instance_request_id:
                sys.stderr.write("Disqualifying instance %s: spot\n" % ( instance.id ) )
            else:
                 **if instance.vpc_id:**
                       print "Does not support vpc yet, please be careful when trusting these results"
                else:
                      az = instance.placement
                      instance_type = instance.instance_type
                      running_instances[ (instance_type, az ) ] = running_instances.get( (instance_type, az ) , 0 ) + 1


   # pprint( running_instances )

它使我正在运行的实例为空,而没有保留的实例也为空,但是打印未使用的保留实例.

It gives me running instances as empty and not reserved instance also empty, but printing unused reserved instances.

当我使用相同的代码而不检查if instance.vpc_id时,如下所示:

When I use the same code without checking if instance.vpc_id, like this:

            running_instances = {}
            for reservation in reservations:
            for instance in reservation.instances:
            if instance.state != "running":
                sys.stderr.write("Disqualifying instance %s: not running\n" % ( instance.id ) )
            elif instance.spot_instance_request_id:
                   sys.stderr.write("Disqualifying instance %s: spot\n" % ( instance.id ) )
            else:
                 az = instance.placement
                 instance_type = instance.instance_type
                 running_instances[ (instance_type, az ) ] = running_instances.get( (instance_type, az ) , 0 ) + 1


           # pprint( running_instances )

它为我提供了正在运行的实例"列表,而不是创建的实例.但是它不会显示未使用的保留实例.仅显示您没有未使用的预留实例".

It gives me a Running instances list and not created instances. But it does not shows unused reserved instances. Just displays "you have no unused reserved instances".

使用和不使用instance.vpc_id进行检查时,为什么会得到不同的结果?哪个是对的?

Why am I getting a different result when I am checking with and without instance.vpc_id? Which one is right?

实际上,它是通过比较正在运行的实例和保留的实例部分来检查未使用的实例的.

Actually it is checking out unutilized instances by comparing running and reserved instances part.

竞价型实例又是什么意思,为什么我们也必须忽略竞价型实例?

Also what is meant by spot instances, why we have to ignore spot instances too?

推荐答案

我不会遍历代码(使用该代码是您的选择),但是我将解释一些可能会使事情变得更容易的概念了解.

I'm not going to go through the code (it is your choice to use that code), but I will explain a few concepts that might make things easier to understand.

Amazon EC2预留实例是对某些Amazon EC2容量的预购买.通过购买预留实例,您有权免费使用匹配的Amazon EC2实例(因为预留实例是按年或按月收费).

An Amazon EC2 Reserved Instance is a pre-purchase of certain Amazon EC2 capacity. By purchasing the Reserved Instance, you are entitled to use a matching Amazon EC2 instance at no hourly cost (because the Reserved Instance is charged Annually or Monthly).

无需提名哪个实例是保留的".而是,AWS计费系统查看每小时使用的EC2实例,并将其与购买的预留实例容量进行比较.如果您拥有与使用的实例相匹配的预留实例,则该实例无需按小时收费.匹配是通过实例类型,操作系统和可选的可用区来完成的.

There is no need to nominate which instance is 'reserved'. Rather, the AWS billing system looks at the EC2 instances used every hour and compares it with purchased Reserved Instance capacity. If you own a Reserved Instance that matches an instance that was used, then there is no hourly charge for that instance. The match is done by Instance Type, Operating System and optionally Availability Zone.

如果您拥有一个预留实例,但运行了两个匹配的EC2实例,则该小时仅一个 EC2实例与预留实例匹配.另一个EC2实例按正常的按需计费.

If you own one Reserved Instance but run two matching EC2 instances, only one EC2 instance for that hour is matched with the Reserved Instance. The other EC2 instance is charged at normal On-Demand rates.

因此,未使用的预留实例仅表示您已购买了预留实例,并且当前当前运行的EC2实例数量不及预留实例的数量.因此,您可以免费运行其他EC2实例(因为它已通过预留实例预付费).

Therefore, an unused Reserved Instance simply means that you have purchased Reserved Instance(s) and you are not currently running as many EC2 instances as the number of Reserved Instances. You could, therefore, run additional EC2 instances at no additional charge (since it has been pre-paid via a Reserved Instance).

Amazon EC2实例具有自己的定价方法,该定价方法基于实例的当前竞价价格(基于实例类型和可用区).竞价型实例将永远不会消耗预留实例的容量,因此应从未使用的"预留实例的任何计算中排除它们.

Amazon EC2 instances launched as Spot Instances have their own pricing method, based upon the current Spot Price for the instance based on its Instance Type and Availability Zone. Spot Instances will never consume Reserved Instance capacity, so they should be excluded from any calculation of "unused" Reserved Instances.

类似地,未运行的EC2实例在计算未使用的预留实例时也应被忽略.

Similarly, an EC2 instance that is not running should also be ignored for calculating unused Reserved Instances.

对于脚本中的instance.vpc_id行,该脚本似乎写于2012年,无法正确处理将Amazon EC2实例启动到Amazon VPC中的情况.如今,默认情况是使用Amazon VPC,因此我不建议使用此脚本,因为该脚本已过期且无法处理此用例.

As to the instance.vpc_id line in the script, it appears that this script was written in 2012 and does not correctly handle situations where an Amazon EC2 instance is launched into an Amazon VPC. These days, the default is to use an Amazon VPC so I would not recommend using this script since it is out-of-date and does not handle this use-case.

相反,我建议使用保留实例利用率AWS管理控制台中提供的报告,可以提供您寻求的信息:

Instead, I would recommend using Reserved Instance Utilization Reports provided within the AWS Management Console, which can provide the information you seek:

这篇关于未使用的AWS预留实例中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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