awslimitchecker.services.base module

class awslimitchecker.services.base._AwsService(warning_threshold, critical_threshold, boto_connection_kwargs, quotas_client)[source]

Bases: awslimitchecker.connectable.Connectable

Describes an AWS service and its limits, and provides methods to query current utilization.

Constructors of _AwsService subclasses must not make any external connections; these must be made lazily as needed in other methods. _AwsService subclasses should be usable without any external network connections.

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.
  • boto_connection_kwargs (dict) – Dictionary of keyword arguments to pass to boto connection methods.
  • quotas_client (ServiceQuotasClient or None) – Instance of ServiceQuotasClient
__init__(warning_threshold, critical_threshold, boto_connection_kwargs, quotas_client)[source]

Describes an AWS service and its limits, and provides methods to query current utilization.

Constructors of _AwsService subclasses must not make any external connections; these must be made lazily as needed in other methods. _AwsService subclasses should be usable without any external network connections.

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.
  • boto_connection_kwargs (dict) – Dictionary of keyword arguments to pass to boto connection methods.
  • quotas_client (ServiceQuotasClient or None) – Instance of ServiceQuotasClient
__metaclass__

alias of abc.ABCMeta

__module__ = 'awslimitchecker.services.base'
_cloudwatch_connection()[source]

Return a connected CloudWatch client instance. ONLY to be used by _get_cloudwatch_usage_latest().

_get_cloudwatch_usage_latest(dimensions, metric_name='ResourceCount', period=60)[source]

Given some metric dimensions, return the value of the latest data point for the AWS/Usage metric specified.

Parameters:
  • dimensions (list) – list of dicts; dimensions for the metric
  • metric_name (str) – AWS/Usage metric name to get
  • period (int) – metric period
Returns:

return the metric value (float or int), or None if it cannot be retrieved

Return type:

float, int or None

_set_ta_limit(limit_name, value)[source]

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

This method should only be called by TrustedAdvisor.

Parameters:
  • limit_name (str) – the name of the limit to override the value for
  • value (int) – the Trusted Advisor limit value
Raises:

ValueError if limit_name is not known to this service

_update_service_quotas()[source]

Update all limits for this service via the Service Quotas service.

api_name = 'baseclass'

the AWS API name for the service

check_thresholds()[source]

Checks current usage against configured thresholds for all limits for this service.

Returns:a dict of limit name to AwsLimit instance for all limits that crossed one or more of their thresholds.
Return type:dict of AwsLimit
current_account_id

Return the numeric Account ID for the account that we are currently running against.

Returns:current account ID
Return type:str
find_usage()[source]

Determine the current usage for each limit of this service, and update the current_usage property of each corresponding AwsLimit instance.

This method MUST set self._have_usage = True.

If the boto3 method being called returns a dict response that can include ‘NextToken’ or another pagination marker, it should be called through paginate_dict() with the appropriate parameters.

get_limits()[source]

Return all known limits for this service, as a dict of their names to AwsLimit objects.

All limits must have self.warning_threshold and self.critical_threshold passed into them.

Returns:dict of limit names to AwsLimit objects
Return type:dict
quotas_service_code = None

the service code for Service Quotas, or None

required_iam_permissions()[source]

Return a list of IAM Actions required for this Service to function properly. All Actions will be shown with an Effect of “Allow” and a Resource of “*”.

Returns:list of IAM Action strings
Return type:list
service_name = 'baseclass'

awslimitchecker’s name for the service

set_limit_override(limit_name, value, override_ta=True)[source]

Set a new limit value for the specified limit, overriding the default. If override_ta is True, also use this value instead of any found by Trusted Advisor. This method simply passes the data through to the set_limit_override() method of the underlying AwsLimit instance.

Parameters:
  • limit_name (str) – the name of the limit to override the value for
  • value (int) – the new value to set for the limit
  • override_ta (bool) – whether or not to also override Trusted Advisor information
Raises:

ValueError if limit_name is not known to this service

set_threshold_override(limit_name, warn_percent=None, warn_count=None, crit_percent=None, crit_count=None)[source]

Override the default warning and critical thresholds used to evaluate the specified 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