awslimitchecker.limit module

class awslimitchecker.limit.AwsLimit(name, service, default_limit, def_warning_threshold, def_critical_threshold, limit_type=None, limit_subtype=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 (string) – the name of this limit (may contain spaces); if possible, this should be the name used by AWS, i.e. TrustedAdvisor
  • service – the _AwsService class that this limit is for
  • default_limit (int) – 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 – resource sub-type for this limit, if applicable, such as “t2.micro” or “SecurityGroup”
Raises:

ValueError

__dict__ = dict_proxy({'set_limit_override': <function set_limit_override at 0x7ff36fc82050>, '__module__': 'awslimitchecker.limit', 'get_limit': <function get_limit at 0x7ff36fc821b8>, 'get_current_usage_str': <function get_current_usage_str at 0x7ff36fc822a8>, '_set_ta_limit': <function _set_ta_limit at 0x7ff36fc820c8>, '__weakref__': <attribute '__weakref__' of 'AwsLimit' objects>, 'check_thresholds': <function check_thresholds at 0x7ff36fc82500>, 'get_criticals': <function get_criticals at 0x7ff36fc825f0>, 'get_current_usage': <function get_current_usage at 0x7ff36fc82230>, '__dict__': <attribute '__dict__' of 'AwsLimit' objects>, 'set_threshold_override': <function set_threshold_override at 0x7ff36fc82488>, '_reset_usage': <function _reset_usage at 0x7ff36fc82398>, 'get_limit_source': <function get_limit_source at 0x7ff36fc82140>, 'get_warnings': <function get_warnings at 0x7ff36fc82578>, '_get_thresholds': <function _get_thresholds at 0x7ff36fc82410>, '_add_current_usage': <function _add_current_usage at 0x7ff36fc82320>, '__doc__': None, '__init__': <function __init__ at 0x7ff36fc75f50>})
__init__(name, service, default_limit, def_warning_threshold, def_critical_threshold, limit_type=None, limit_subtype=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 (string) – the name of this limit (may contain spaces); if possible, this should be the name used by AWS, i.e. TrustedAdvisor
  • service – the _AwsService class that this limit is for
  • default_limit (int) – 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 – resource sub-type for this limit, if applicable, such as “t2.micro” or “SecurityGroup”
Raises:

ValueError

__module__ = 'awslimitchecker.limit'
__weakref__

list of weak references to the object (if defined)

_add_current_usage(value, 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 (string) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
  • aws_type (string) –

    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_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
check_thresholds()[source]

Check this limit’s current usage against the specified default thresholds, and any custom theresholds that have been set on the 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.

Parameters:
  • default_warning (int or float percentage) – default warning threshold in percentage; usage higher than this percent of the limit will be considered a warning
  • default_critical (int or float percentage) – default critical threshold in percentage; usage higher than this percent of the limit will be considered a critical
Returns:

False if any thresholds 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:string
get_limit()[source]

Returns the effective limit value for this Limit, taking into account limit overrides and Trusted Advisor data.

Returns:effective limit value
Return type:int
get_limit_source()[source]

Return SOURCE_DEFAULT if get_limit() returns the default limit, SOURCE_OVERRIDE if it returns a manually-overridden limit, or SOURCE_TA if it returns a limit from Trusted Advisor.

Returns:one of SOURCE_DEFAULT, SOURCE_OVERRIDE, or SOURCE_TA
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
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.

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
class awslimitchecker.limit.AwsLimitUsage(limit, value, 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
  • resource_id (string) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
  • aws_type (string) –

    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__ = dict_proxy({'__ne__': <function __ne__ at 0x7ff36fc82848>, '__module__': 'awslimitchecker.limit', '__weakref__': <attribute '__weakref__' of 'AwsLimitUsage' objects>, '__str__': <function __str__ at 0x7ff36fc82758>, 'get_value': <function get_value at 0x7ff36fc826e0>, '__init__': <function __init__ at 0x7ff36fc82668>, '__gt__': <function __gt__ at 0x7ff36fc828c0>, '__dict__': <attribute '__dict__' of 'AwsLimitUsage' objects>, '__lt__': <function __lt__ at 0x7ff36fc82938>, '__eq__': <function __eq__ at 0x7ff36fc827d0>, '__doc__': None, '__ge__': <function __ge__ at 0x7ff36fc829b0>})
__eq__(other)[source]
__ge__(other)[source]
__gt__(other)[source]
__init__(limit, value, 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
  • resource_id (string) – If there can be multiple usage values for one limit, an AWS ID for the resource this instance describes
  • aws_type (string) –

    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]
__module__ = 'awslimitchecker.limit'
__ne__(other)[source]
__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:string
__weakref__

list of weak references to the object (if defined)

get_value()[source]

Get the current usage value

Returns:current usage value
Return type:int or float
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