awslimitchecker.checker module¶
-
class
awslimitchecker.checker.
AwsLimitChecker
(warning_threshold=80, critical_threshold=99, account_id=None, account_role=None, region=None, external_id=None)[source]¶ Bases:
object
Main AwsLimitChecker class - this should be the only externally-used portion of awslimitchecker.
Constructor builds
self.services
as a dict of service_name (str) to_AwsService
instance, and sets limit thresholds.Parameters: - warning_threshold (int) – the default warning threshold, as an integer percentage, for any limits without a specifically-set threshold.
- critical_threshold (int) – the default critical threshold, as an integer percentage, for any limits without a specifically-set threshold.
- account_id (str) – AWS Account ID (12-digit string, currently numeric) for the account to connect to (destination) via STS
- account_role (str) – the name of an IAM Role (in the destination account) to assume
- region (str) – AWS region name to connect to
- external_id (str) – (optional) the External ID string to use when assuming a role via STS.
-
__dict__
= dict_proxy({'set_limit_override': <function set_limit_override at 0x7f3a51ca8cf8>, '__module__': 'awslimitchecker.checker', 'find_usage': <function find_usage at 0x7f3a51ca8c08>, 'get_service_names': <function get_service_names at 0x7f3a51ca8b90>, 'set_threshold_overrides': <function set_threshold_overrides at 0x7f3a51ca8d70>, 'get_version': <function get_version at 0x7f3a51ca8a28>, 'check_thresholds': <function check_thresholds at 0x7f3a51ca8e60>, 'set_threshold_override': <function set_threshold_override at 0x7f3a51ca8de8>, 'get_limits': <function get_limits at 0x7f3a51ca8b18>, 'set_limit_overrides': <function set_limit_overrides at 0x7f3a51ca8c80>, '__dict__': <attribute '__dict__' of 'AwsLimitChecker' objects>, 'get_required_iam_policy': <function get_required_iam_policy at 0x7f3a51ca8ed8>, '__weakref__': <attribute '__weakref__' of 'AwsLimitChecker' objects>, '__doc__': None, '__init__': <function __init__ at 0x7f3a51ca89b0>, 'get_project_url': <function get_project_url at 0x7f3a51ca8aa0>})¶
-
__init__
(warning_threshold=80, critical_threshold=99, account_id=None, account_role=None, region=None, external_id=None)[source]¶ Main AwsLimitChecker class - this should be the only externally-used portion of awslimitchecker.
Constructor builds
self.services
as a dict of service_name (str) to_AwsService
instance, and sets limit thresholds.Parameters: - warning_threshold (int) – the default warning threshold, as an integer percentage, for any limits without a specifically-set threshold.
- critical_threshold (int) – the default critical threshold, as an integer percentage, for any limits without a specifically-set threshold.
- account_id (str) –
AWS Account ID (12-digit string, currently numeric) for the account to connect to (destination) via STS
- account_role (str) –
the name of an IAM Role (in the destination account) to assume
- region (str) – AWS region name to connect to
- external_id (str) –
(optional) the External ID string to use when assuming a role via STS.
-
__module__
= 'awslimitchecker.checker'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
check_thresholds
(service=None, use_ta=True)[source]¶ Check all limits and current usage against their specified thresholds; return all
AwsLimit
instances that have crossed one or more of their thresholds.If
service
is specified, the returned dict has one element, the service name, whose value is a nested dict as described below; otherwise it includes all known services.The returned
AwsLimit
objects can be interrogated for their limits (get_limit()
) as well as the details of usage that crossed the thresholds (get_warnings()
andget_criticals()
).Parameters: Returns: dict of service name (string) to nested dict of limit name (string) to limit (
AwsLimit
)Return type:
-
find_usage
(service=None, use_ta=True)[source]¶ For each limit in the specified service (or all services if
service
isNone
), query the AWS API viaboto
and find the current usage amounts for that limit.This method updates the
current_usage
attribute of theAwsLimit
objects for each service, which can then be queried usingget_limits()
.Parameters: - service (
None
, orstring
service name to get) –_AwsService
name, orNone
to check all services. - use_ta (bool) – check Trusted Advisor for information on limits
- service (
-
get_limits
(service=None, use_ta=True)[source]¶ Return all
AwsLimit
objects for the given service name, or for all services ifservice
is None.If
service
is specified, the returned dict has one element, the service name, whose value is a nested dict as described below.Parameters: Returns: dict of service name (string) to nested dict of limit name (string) to limit (
AwsLimit
)Return type:
-
get_project_url
()[source]¶ Return the URL for the awslimitchecker project.
Returns: URL of where to find awslimitchecker Return type: string
-
get_required_iam_policy
()[source]¶ Return an IAM policy granting all of the permissions needed for awslimitchecker to fully function. This returns a dict suitable for json serialization to a valid IAM policy.
Internally, this calls
required_iam_permissions()
on each_AwsService
instance.Returns: dict representation of IAM Policy Return type: dict
-
get_service_names
()[source]¶ Return a list of all known service names
Returns: list of service names Return type: list
-
get_version
()[source]¶ Return the version of awslimitchecker currently running.
Returns: current awslimitchecker version Return type: string
-
set_limit_override
(service_name, limit_name, value, override_ta=True)[source]¶ Set a manual override on an AWS service limits, i.e. if you had limits increased by AWS support.
This method calls
set_limit_override()
on the corresponding _AwsService instance.Explicitly set limit overrides using this method will take precedence over default limits. They will also take precedence over limit information obtained via Trusted Advisor, unless
override_ta
is set toFalse
.Parameters: Raises: ValueError if limit_name is not known to the service instance
-
set_limit_overrides
(override_dict, override_ta=True)[source]¶ Set manual overrides on AWS service limits, i.e. if you had limits increased by AWS support. This takes a dict in the same form as that returned by
get_limits()
, i.e. service_name (str) keys to nested dict of limit_name (str) to limit value (int) like:{ 'EC2': { 'Running On-Demand t2.micro Instances': 1000, 'Running On-Demand r3.4xlarge Instances': 1000, } }
Internally, for each limit override for each service in
override_dict
, this method callsset_limit_override()
on the corresponding _AwsService instance.Explicitly set limit overrides using this method will take precedence over default limits. They will also take precedence over limit information obtained via Trusted Advisor, unless
override_ta
is set toFalse
.Parameters: Raises: exceptions.ValueError
if limit_name is not known to the service instance
-
set_threshold_override
(service_name, limit_name, warn_percent=None, warn_count=None, crit_percent=None, crit_count=None)[source]¶ Set a manual override on the threshold (used for determining warning/critical status) for a specific limit. See
AwsLimitChecker
for information on Warning and Critical thresholds.Parameters: - service_name (string) – the name of the service to override limit for
- limit_name (string) – the name of the limit to override:
- 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
-
set_threshold_overrides
(override_dict)[source]¶ Set manual overrides on the threshold (used for determining warning/critical status) a dict of limits. See
AwsLimitChecker
for information on Warning and Critical thresholds.Dict is composed of service name keys (string) to dict of limit names (string), to dict of threshold specifications. Each threhold specification dict can contain keys ‘warning’ or ‘critical’, each having a value of a dict containing keys ‘percent’ or ‘count’, to an integer value.
Example:
{ 'EC2': { 'SomeLimit': { 'warning': { 'percent': 80, 'count': 8, }, 'critical': { 'percent': 90, 'count': 9, } } } }
Parameters: override_dict (dict) – nested dict of threshold overrides