- nab3.aws
- nab3.helpers.cloud_watch
- nab3.helpers.ec2
- nab3.helpers.ecs
- nab3.service
- nab3.service.ASG
- nab3.service.Alarm
- nab3.service.AppAutoScalePolicy
- nab3.service.AutoScalePolicy
- nab3.service.EC2Instance
- nab3.service.ECSCluster
- nab3.service.ECSInstance
- nab3.service.ECSService
- nab3.service.ECSTask
- nab3.service.ElasticacheCluster
- nab3.service.LaunchConfiguration
- nab3.service.LoadBalancer
- nab3.service.LoadBalancerClassic
- nab3.service.Metric
- nab3.service.Pricing
- nab3.service.SecurityGroup
- nab3.utils
- nab3.mixin
Connection manager tied to a boto3 session instance. When a Service.list/get method is called a boto3 client is lazy loaded into the AWS instance and is used by any other services that required that same client.
Returns a list of supported service classes
:return: list<str>
md_alarms(scalable_object, start_date=datetime.datetime(2020, 8, 11, 9, 35, 58, 35700), end_date=datetime.datetime(2020, 9, 10, 9, 35, 58, 35716)) -> str
Generate a markdown summary of alarms for a scalable object.
Example:
ecs_cluster = await AWS.ecs_cluster.get(name='sample', with_related=[
'asg', 'scaling_policies', 'services', 'services__scaling_policies'
])
md_output = f"# {ecs_cluster.name}"
alarm_str = await md_alarms(ecs_cluster)
with open(f'{ecs_cluster.name}.md', 'w') as f:
f.write(f'{md_output}/n{alarm_str}')
Creates a markdown summary based on the provided get_statistics list response
:param metric_obj_list:
:param metric_name:
:param include_table: Include an md table containing the datapoints used to generate the summary.
Columns: Time Unit Average Maximum
:return:
set_n_service_stats(service_list, stat_list: list = None, start_date=datetime.datetime(2020, 8, 11, 9, 35, 58, 35723), end_date=datetime.datetime(2020, 9, 10, 9, 35, 58, 35725))
Retrieves all statistics passed in stat_list for each of the provided services in service_list.
For each in service_list: service_obj.stats = [dict(metric=str, stats=Metric())]
:param service_list:
:param stat_list:
:param start_date:
:param end_date:
:return: service_list
set_service_stats(service_obj, stat_list: list = None, start_date=datetime.datetime(2020, 8, 11, 9, 35, 58, 35719), end_date=datetime.datetime(2020, 9, 10, 9, 35, 58, 35721))
Retrieves all statistics passed in stat_list for the service_obj.
service_obj.stats = [dict(metric=str, stats=Metric())]
:param service_obj:
:param stat_list:
:param start_date:
:param end_date:
:return: service_obj
Creates a md table str containing all instances with their IPs for an scalable object
Creates a md summary for a scalable object containing all security groups, the objects' SG rules, and the SG rules of services it has access to
Creates a md table str for a list of security groups that contains the SG rules for each SG
:param ecs_cluster: ECSCluster object
:param display_alarms: bool Default(True) - Display cloudwatch alarms for the last 30 days
:param display_service_events: bool Default(True) - Display the 50 most recent events of each service
:return:
:param ecs_service: ECSService object
:param display_alarms: bool Default(True) - Display service cloudwatch alarms for the last 30 days
:param display_events: bool Default(True) - Display the 50 most recent events of the service
:return:
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.describe_auto_scaling_groups
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.describe_launch_configurations
Retrieves the instances related security groups.
stored as the instance attribute `obj.security_groups`
:return: list<SecurityGroup>
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudwatch.html#CloudWatch.Client.describe_alarm_history
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/application-autoscaling.html#ApplicationAutoScaling.Client.describe_scaling_policies
Scalable Dimension options:
ecs:service:DesiredCount
ec2:spot-fleet-request:TargetCapacity
elasticmapreduce:instancegroup:InstanceCount
appstream:fleet:DesiredCapacity
dynamodb:table:ReadCapacityUnits
dynamodb:table:WriteCapacityUnits
dynamodb:index:ReadCapacityUnits
dynamodb:index:WriteCapacityUnits
rds:cluster:ReadReplicaCount
sagemaker:variant:DesiredInstanceCount
custom-resource:ResourceType:Property
comprehend:document-classifier-endpoint:DesiredInferenceUnits
lambda:function:ProvisionedConcurrency
cassandra:table:ReadCapacityUnits
cassandra:table:WriteCapacityUnits
AppAutoScalePolicy.get_alarms(self, start_date, end_date, item_type=None, alarm_types=[], sort_desc=True)
:param start_date: StartDate=datetime(2015, 1, 1)
:param end_date: EndDate=datetime(2015, 1, 1)
:param item_type: HistoryItemType='ConfigurationUpdate StateUpdate Action'
:param alarm_types: AlarmTypes=['CompositeAlarm MetricAlarm']
:param sort_desc: bool -> ScanBy='TimestampDescending TimestampAscending'
:return:
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.describe_policies
AutoScalePolicy.get_alarms(self, start_date, end_date, item_type=None, alarm_types=[], sort_desc=True)
:param start_date: StartDate=datetime(2015, 1, 1)
:param end_date: EndDate=datetime(2015, 1, 1)
:param item_type: HistoryItemType='ConfigurationUpdate StateUpdate Action'
:param alarm_types: AlarmTypes=['CompositeAlarm MetricAlarm']
:param sort_desc: bool -> ScanBy='TimestampDescending TimestampAscending'
:return:
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_instances
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.list_clusters
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.describe_clusters
Retrieves the instances asg.
stored as the instance attribute `obj.asg`
if self.scaling_policies.loaded:
return self.scaling_policies
if not self.security_groups.loaded:
await self.fetch('security_groups')
filter_list = [sg.id for sg in self.security_groups]
if not filter_list:
return self.accessible_resources
self.accessible_resources = await self.accessible_resources.service_class.list(Filters=[dict(
Name='ip-permission.group-id',
Values=filter_list
)])
return self.accessible_resources
:return: ASG
Retrieves the cluster's instances.
stored as the instance attribute `obj.instances`
:return: list<instances>
Retrieves the cluster's scaling policies.
stored as the instance attribute `obj.scaling_policies`
:return: list<scaling_policies>
Retrieves the cluster's services.
stored as the instance attribute `obj.services`
:return: list<services>
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.list_container_instances
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.describe_container_instances
For filter see docs.aws.amazon.com/AmazonECS/latest/developerguide/cluster-query-language.html but...
It appears to be client side so it's likely easier to use nab3.Filter
Valid status options:
ACTIVE
DRAINING
REGISTERING
DEREGISTERING
REGISTRATION_FAILED
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.list_services
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.describe_services
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.list_tasks
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.describe_tasks
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elasticache.html#ElastiCache.Client.describe_cache_clusters
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.describe_launch_configurations
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.describe_load_balancers
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.describe_load_balancers
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudwatch.html#CloudWatch.Client.list_metrics
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudwatch.html#CloudWatch.Client.get_metric_statistics
docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#dimension-combinations
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/pricing.html#Pricing.Client.get_products
boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_security_groups
Convert a string from camel case to kebab case
Convert a string from camel case to snake case
describe_resource(search_fnc, id_key: str, id_list: list, search_kwargs: dict, chunk_size: int = 50) -> list
Chunks up describe operation and runs requests concurrently.
:param search_fnc: Name of the boto3 function e.g. describe_auto_scaling_groups
:param id_key: Name of the key used for describe operation e.g. AutoScalingGroupNames
:param id_list: List of id values
:param search_kwargs: Additional arguments to pass to the describe operation like Filter, MaxRecords, or Tags
:param chunk_size: Used to set request size. Cannot exceed the operation's MaxRecords or there may be data loss.
:return: list<boto3 describe response>
paginated_search(search_fnc, search_kwargs: dict, response_key: str, max_results: int = None) -> list
Retrieve and aggregate each paged response, returning a single list of each response object :param search_fnc: :param search_kwargs: :param response_key: :param max_results: :return:
Convert a string from snake_case to camelBack
Convert a string from snake_case to CamelCap
Mixin to provide app auto scale integrations for a service class
MetricMixin.get_statistics(self, metric_name: str, start_time: datetime.datetime = datetime.datetime(2020, 9, 10, 11, 35, 57, 758116), end_time: datetime.datetime = datetime.datetime(2020, 9, 10, 14, 35, 57, 758129), interval_as_seconds: int = 300, **kwargs) -> list
:param metric_name:
:param start_time:
:param end_time:
:param interval_as_seconds:
:param kwargs:
:return: