awslimitchecker.limit module

class awslimitchecker.limit.AwsLimit(name, service, default_limit, def_warning_threshold, def_critical_threshold, limit_type=None, limit_subtype=None, ta_service_name=None, ta_limit_name=None)[source]

Bases: object

Describes one specific AWS service limit, as well as its current utilization, default limit, thresholds, and any Trusted Advisor information about this limit.

Parameters:
  • name (str) – the name of this limit (may contain spaces); if possible, this should be the name used by AWS, i.e. TrustedAdvisor
  • service (_AwsService) – the _AwsService class that this limit is for
  • default_limit (int, or None if unlimited) – the default value of this limit for new accounts
  • def_warning_threshold (int) – the default warning threshold, as an integer percentage.
  • def_critical_threshold (int) – the default critical threshold, as an integer percentage.
  • limit_type – the type of resource this limit describes, specified as one of the type names used in CloudFormation # noqa such as “AWS::EC2::Instance” or “AWS::RDS::DBSubnetGroup”.
  • limit_subtype (str) – resource sub-type for this limit, if applicable, such as “t2.micro” or “SecurityGroup”
  • ta_service_name (str) – The service name returned by Trusted Advisor for this limit, if different from the name of service
  • ta_limit_name (str) – The limit name returned by Trusted Advisor for this limit, if different from name.
Raises:

ValueError

__dict__ = mappingproxy({'__module__': 'awslimitchecker.limit', '__init__': <function AwsLimit.__init__>, 'set_limit_override': <function AwsLimit.set_limit_override>, '_set_ta_limit': <function AwsLimit._set_ta_limit>, '_set_ta_unlimited': <function AwsLimit._set_ta_unlimited>, '_set_api_limit': <function AwsLimit._set_api_limit>, 'get_limit_source': <function AwsLimit.get_limit_source>, 'get_limit': <function AwsLimit.get_limit>, 'has_resource_limits': <function AwsLimit.has_resource_limits>, 'get_current_usage': <function AwsLimit.get_current_usage>, 'get_current_usage_str': <function AwsLimit.get_current_usage_str>, '_add_current_usage': <function AwsLimit._add_current_usage>, '_reset_usage': <function AwsLimit._reset_usage>, '_get_thresholds': <function AwsLimit._get_thresholds>, 'set_threshold_override': <function AwsLimit.set_threshold_override>, 'check_thresholds': <function AwsLimit.check_thresholds>, 'get_warnings': <function AwsLimit.get_warnings>, 'get_criticals': <function AwsLimit.get_criticals>, 'ta_service_name': <property object>, 'ta_limit_name': <property object>, '__dict__': <attribute '__dict__' of 'AwsLimit' objects>, '__weakref__': <attribute '__weakref__' of 'AwsLimit' objects>, '__doc__': None})
__init__(name, service, default_limit, def_warning_threshold, def_critical_threshold, limit_type=None, limit_subtype=None, ta_service_name=None, ta_limit_name=None)[source]

Describes one specific AWS service limit, as well as its current utilization, default limit, thresholds, and any Trusted Advisor information about this limit.

Parameters:
  • name (str) – the name of this limit (may contain spaces); if possible, this should be the name used by AWS, i.e. TrustedAdvisor
  • service (_AwsService) – the _AwsService class that this limit is for
  • default_limit (int, or None if unlimited) – the default value of this limit for new accounts
  • def_warning_threshold (int) – the default warning threshold, as an integer percentage.
  • def_critical_threshold (int) – the default critical threshold, as an integer percentage.
  • limit_type

    the type of resource this limit describes, specified as one of the type names used in CloudFormation # noqa such as “AWS::EC2::Instance” or “AWS::RDS::DBSubnetGroup”.

  • limit_subtype (str) – resource sub-type for this limit, if applicable, such as “t2.micro” or “SecurityGroup”
  • ta_service_name (str) – The service name returned by Trusted Advisor for this limit, if different from the name of service
  • ta_limit_name (str) – The limit name returned by Trusted Advisor for this limit, if different from name.
Raises:

ValueError

__module__ = 'awslimitchecker.limit'
__weakref__

list of weak references to the object (if defined)

_add_current_usage(value, maximum=None, resource_id=None, aws_type=None)[source]

Add a new current usage value for this limit.

Creates a new AwsLimitUsage instance and appends it to the internal list. If more than one usage value is given to this service, they should have id and aws_type set.

This method should only be called from the _AwsService instance that created and manages this Limit.

Parameters:
  • value (int or float) – the numeric usage value
  • resource_id (str) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
  • aws_type (str) –

    if id is not None, the AWS resource type that ID represents. As a convention, we use the AWS Resource Type names used by CloudFormation # noqa

_get_thresholds()[source]

Get the warning and critical thresholds for this Limit.

Return type is a 4-tuple of:

  1. warning integer (usage) threshold, or None
  2. warning percent threshold
  3. critical integer (usage) threshold, or None
  4. critical percent threshold
Return type:tuple
_reset_usage()[source]

Discard all current usage data.

_set_api_limit(limit_value)[source]

Set the value for the limit as reported by the service’s API.

This method should only be called from the Service class.

Parameters:limit_value (int) – the API limit value
_set_ta_limit(limit_value)[source]

Set the value for the limit as reported by Trusted Advisor.

This method should only be called by TrustedAdvisor.

Parameters:limit_value (int) – the Trusted Advisor limit value
_set_ta_unlimited()[source]

Set state to indicate that TrustedAdvisor reports this limit as having no maximum (unlimited).

This method should only be called by TrustedAdvisor.

check_thresholds()[source]

Check this limit’s current usage against the specified default thresholds, and any custom theresholds that have been set on the class instance. Return True if usage is within thresholds, or false if warning or critical thresholds have been surpassed.

This method sets internal variables in this instance which can be queried via get_warnings() and get_criticals() to obtain further details about the thresholds that were crossed.

Note This function returns False if any thresholds were crossed. Please be aware of this when setting threshold overrides to suppress alerts. Each threshold (warn_percent, warn_count, crit_percent, crit_count) that has been set is evaluated individually and the result appended to a list of warnings or criticals, respectively. If any of these evaluations failed, the method returns False.

Returns:False if any thresholds were crossed, True otherwise
Return type:bool
get_criticals()[source]

Return a list of AwsLimitUsage instances that crossed the critical threshold. These objects are comparable and can be sorted.

Return type:list
get_current_usage()[source]

Get the current usage for this limit, as a list of AwsLimitUsage instances.

Returns:list of current usage values
Return type:list of AwsLimitUsage
get_current_usage_str()[source]

Get the a string describing the current usage for this limit.

If no usage has been added for this limit, the result will be “<unknown>”.

If the limit has only one current usage instance, this will be that instance’s __str__() value.

If the limit has more than one current usage instance, this will be the a string of the form max: X (Y) where X is the __str__() value of the instance with the maximum value, and Y is a comma-separated list of the __str__() values of all usage instances in ascending order.

Returns:representation of current usage
Return type:str
get_limit()[source]

Returns the effective limit value for this Limit, taking into account limit overrides and Trusted Advisor data. None is returned for limits that are explicitly unlimited.

Returns:effective limit value, int or None
get_limit_source()[source]

Return SOURCE_DEFAULT if get_limit() returns the default limit, SOURCE_OVERRIDE if it returns a manually-overridden limit, SOURCE_TA if it returns a limit from Trusted Advisor, or SOURCE_API if it returns a limit retrieved from the service’s API.

Returns:one of SOURCE_DEFAULT, SOURCE_OVERRIDE, or SOURCE_TA, or SOURCE_API
Return type:int
get_warnings()[source]

Return a list of AwsLimitUsage instances that crossed the warning threshold. These objects are comparable and can be sorted.

Return type:list
has_resource_limits()[source]

Determines if this limit contains usages with a specified maximum. Some AWS resources have a limit that is a different for each item.

Returns:whether of not some resources have a defined maximum
Return type:bool
set_limit_override(limit_value, override_ta=True)[source]

Set a new value for this limit, to override the default (such as when AWS Support has increased a limit of yours). If override_ta is True, this value will also supersede any found through Trusted Advisor.

Parameters:
  • limit_value (int) – the new limit value
  • override_ta (bool) – whether or not to also override Trusted Advisor information
set_threshold_override(warn_percent=None, warn_count=None, crit_percent=None, crit_count=None)[source]

Override the default warning and critical thresholds used to evaluate this limit’s usage. Theresholds can be specified as a percentage of the limit, or as a usage count, or both.

Note: The percent thresholds (warn_percent and crit_percent) have default values that are set globally for awslimitchecker, unlike the count thresholds. When setting threshold overrides to quiet or suppress alerts for a limit, you must set the percent thresholds. If you only set overrides for the count thresholds, the percent thresholds will continue to be evaluated at their awslimitchecker-wide default, and likely prevent alerts from being suppressed.

see check_thresholds() for further information on threshold evaluation.

Parameters:
  • warn_percent (int) – new warning threshold, percentage used
  • warn_count (int) – new warning threshold, actual count/number
  • crit_percent (int) – new critical threshold, percentage used
  • crit_count (int) – new critical threshold, actual count/number
ta_limit_name

Return the effective Trusted Advisor limit name that this limit’s data will have. This should be self._ta_limit_name if set, otherwise self.name.

Returns:Trusted Advisor limit data name
Return type:str
ta_service_name

Return the effective Trusted Advisor service name that this limit’s data will have. This should be self._ta_service_name if set, otherwise the name of self.service.

Returns:Trusted Advisor service data name
Return type:str
class awslimitchecker.limit.AwsLimitUsage(limit, value, maximum=None, resource_id=None, aws_type=None)[source]

Bases: object

This object describes the usage of an AWS resource, with the capability of containing information about the resource beyond an integer usage.

The simplest case is an account- / region-wide count, such as the number of running EC2 Instances, in which case a simple integer value is sufficient. In this case, the AwsLimit would have one instance of this class for the single value.

In more complex cases, such as the “Subnets per VPC”, the limit is applied by AWS on multiple resources (once per VPC). In this case, the AwsLimit should have one instance of this class per VPC, so we can determine which VPCs have crossed thresholds.

AwsLimitUsage objects are comparable based on their numeric value.

Parameters:
  • limit (AwsLimit) – the AwsLimit that this instance describes
  • value (int or float) – the numeric usage value
  • maximum (int or float) – the numeric maximum value
  • resource_id (str) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
  • aws_type (str) –

    if id is not None, the AWS resource type that ID represents. As a convention, we use the AWS Resource Type names used by CloudFormation # noqa

__dict__ = mappingproxy({'__module__': 'awslimitchecker.limit', '__init__': <function AwsLimitUsage.__init__>, 'get_value': <function AwsLimitUsage.get_value>, 'get_maximum': <function AwsLimitUsage.get_maximum>, '__str__': <function AwsLimitUsage.__str__>, '__eq__': <function AwsLimitUsage.__eq__>, '__ne__': <function AwsLimitUsage.__ne__>, '__gt__': <function AwsLimitUsage.__gt__>, '__lt__': <function AwsLimitUsage.__lt__>, '__ge__': <function AwsLimitUsage.__ge__>, '__dict__': <attribute '__dict__' of 'AwsLimitUsage' objects>, '__weakref__': <attribute '__weakref__' of 'AwsLimitUsage' objects>, '__doc__': None, '__hash__': None})
__eq__(other)[source]

Return self==value.

__ge__(other)[source]

Return self>=value.

__gt__(other)[source]

Return self>value.

__hash__ = None
__init__(limit, value, maximum=None, resource_id=None, aws_type=None)[source]

This object describes the usage of an AWS resource, with the capability of containing information about the resource beyond an integer usage.

The simplest case is an account- / region-wide count, such as the number of running EC2 Instances, in which case a simple integer value is sufficient. In this case, the AwsLimit would have one instance of this class for the single value.

In more complex cases, such as the “Subnets per VPC”, the limit is applied by AWS on multiple resources (once per VPC). In this case, the AwsLimit should have one instance of this class per VPC, so we can determine which VPCs have crossed thresholds.

AwsLimitUsage objects are comparable based on their numeric value.

Parameters:
  • limit (AwsLimit) – the AwsLimit that this instance describes
  • value (int or float) – the numeric usage value
  • maximum (int or float) – the numeric maximum value
  • resource_id (str) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
  • aws_type (str) –

    if id is not None, the AWS resource type that ID represents. As a convention, we use the AWS Resource Type names used by CloudFormation # noqa

__lt__(other)[source]

Return self<value.

__module__ = 'awslimitchecker.limit'
__ne__(other)[source]

Return self!=value.

__str__()[source]

Return a string representation of this object.

If id is not set, return value formatted as a string; otherwise, return a string of the format id=value.

Return type:str
__weakref__

list of weak references to the object (if defined)

get_maximum()[source]

Get the current maximum value

Returns:current maximum value
Return type:int or float
get_value()[source]

Get the current usage value

Returns:current usage value
Return type:int or float
awslimitchecker.limit.SOURCE_API = 3

indicates a limit value that came from the service’s API

awslimitchecker.limit.SOURCE_DEFAULT = 0

indicates a limit value that came from hard-coded defaults in awslimitchecker

awslimitchecker.limit.SOURCE_OVERRIDE = 1

indicates a limit value that came from user-defined limit overrides

awslimitchecker.limit.SOURCE_TA = 2

indicates a limit value that came from Trusted Advisor