awslimitchecker.services.ec2 module

class awslimitchecker.services.ec2._Ec2Service(warning_threshold, critical_threshold, boto_connection_kwargs, quotas_client)[source]

Bases: awslimitchecker.services.base._AwsService

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
__module__ = 'awslimitchecker.services.ec2'
_find_usage_instances_nonvcpu()[source]

calculate On-Demand instance usage for all types and update Limits

_find_usage_instances_vcpu()[source]
_find_usage_networking_eips()[source]
_find_usage_networking_eni_sg()[source]
_find_usage_networking_sgs()[source]

calculate usage for VPC-related things

_find_usage_spot_fleets()[source]

calculate spot fleet request usage and update Limits

_find_usage_spot_instances()[source]

calculate spot instance request usage and update Limits

_get_limits_instances_nonvcpu()[source]

Return a dict of limits for EC2 instances only, for regions using non-vCPU-based (old-style) On Demand Instances limits. This method should only be used internally by :py:meth:~.get_limits`.

Return type:dict
_get_limits_instances_vcpu()[source]

Return a dict of limits for EC2 instances only, for regions using vCPU-based (new-style) On Demand Instances limits. This method should only be used internally by :py:meth:~.get_limits`.

Return type:dict
_get_limits_networking()[source]

Return a dict of VPC-related limits only. This method should only be used internally by :py:meth:~.get_limits`.

Return type:dict
_get_limits_spot()[source]

Return a dict of limits for spot requests only. This method should only be used internally by :py:meth:~.get_limits`.

Return type:dict
_get_reserved_instance_count()[source]

For each availability zone, get the count of current instance reservations of each instance type. Return as a nested dict of AZ name to dict of instance type to reservation count.

Return type:dict
_instance_types()[source]

Return a list of all known EC2 instance types

Returns:list of all valid known EC2 instance types
Return type:list
_instance_usage()[source]

Find counts of currently-running EC2 Instances (On-Demand or Reserved) by placement (Availability Zone) and instance type (size). Return as a nested dict of AZ name to dict of instance type to count.

Return type:dict
_instance_usage_vcpu(ris)[source]

Find counts of currently-running EC2 Instance vCPUs (On-Demand or Reserved) by instance family. Return as a dict of instance family letter to count.

Parameters:ris (dict) – nested dict of reserved instances, as returned by _get_reserved_instance_count()
Return type:dict
_update_limits_from_api()[source]

Query EC2’s DescribeAccountAttributes API action, and update limits with the quotas returned. Updates self.limits.

_use_vcpu_limits

Return whether or not to use the new vCPU-based limits.

Returns:whether to use vCPU-based limits (True) or older per-instance-type limits (False)
Return type:bool
api_name = 'ec2'
default_limit_name = 'Running On-Demand All Standard (A, C, D, H, I, M, R, T, Z) instances'

Name of default limit for all other (standard) instance families.

default_quota_name = 'Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances'

Name of default Service Quota for all other (standard) families.

find_usage()[source]

Determine the current usage for each limit of this service, and update corresponding Limit via _add_current_usage().

get_limits()[source]

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

Returns:dict of limit names to AwsLimit objects
Return type:dict
instance_family_to_limit_name = {'f': 'Running On-Demand All F instances', 'g': 'Running On-Demand All G instances', 'p': 'Running On-Demand All P instances', 'x': 'Running On-Demand All X instances'}

Mapping of lower-case instance family character (instance type first character) to limit name for that family.

instance_family_to_quota_name = {'f': 'Running On-Demand F instances', 'g': 'Running On-Demand G instances', 'p': 'Running On-Demand P instances', 'x': 'Running On-Demand X instances'}

Mapping of lower-case instance family character to Service Quotas quota name for that family.

no_quotas_types = ['c5d.12xlarge', 'c5d.24xlarge', 'c5d.metal', 'cc1.4xlarge', 'cg1.4xlarge', 'cr1.8xlarge', 'g4dn.metal', 'hi1.4xlarge', 'hs1.8xlarge', 'm5dn.metal', 'm5n.metal', 'r5dn.metal', 'r5n.metal', 'u-18tb1.metal', 'u-24tb1.metal']

List of instance types that aren’t exposed via Service Quotas

quotas_service_code = 'ec2'
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 = 'EC2'