Skip to content

Latest commit

 

History

History
506 lines (327 loc) · 20.3 KB

API_REFERENCE.md

File metadata and controls

506 lines (327 loc) · 20.3 KB

nab3.aws

nab3.aws.AWS(self, session: boto3.session.Session = Session(region_name='us-east-1'))

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.

AWS.service_options() -> list

Returns a list of supported service classes :return: list<str>

nab3.helpers.cloud_watch

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}')

md_statistics_summary(metric_obj_list: list, include_table: bool = True) -> 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

nab3.helpers.ec2

md_autoscale_ips(asg_object)

Creates a md table str containing all instances with their IPs for an scalable object

md_autoscale_sgs(asg_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

md_security_group_table(sg_list: list, id_filter: list = [], is_accessible_resources: bool = False)

Creates a md table str for a list of security groups that contains the SG rules for each SG

nab3.helpers.ecs

md_ecs_cluster_summary(ecs_cluster, display_alarms=True, display_service_events=False) -> str

: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:

md_ecs_service_summary(ecs_service, display_alarms=True, display_events=True) -> str

: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:

nab3.service

nab3.service.ASG(self, **kwargs)

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

ASG.load_security_groups(self)

Retrieves the instances related security groups.

    stored as the instance attribute `obj.security_groups`

    :return: list<SecurityGroup>

nab3.service.Alarm(self, **kwargs)

boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudwatch.html#CloudWatch.Client.describe_alarm_history

nab3.service.AppAutoScalePolicy(self, **kwargs)

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:

nab3.service.AutoScalePolicy(self, **kwargs)

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:

nab3.service.EC2Instance(self, **kwargs)

boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_instances

nab3.service.ECSCluster(self, **kwargs)

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

ECSCluster.load_asg(self)

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

ECSCluster.load_instances(self)

Retrieves the cluster's instances.

    stored as the instance attribute `obj.instances`

    :return: list<instances>

ECSCluster.load_scaling_policies(self)

Retrieves the cluster's scaling policies.

    stored as the instance attribute `obj.scaling_policies`

    :return: list<scaling_policies>

ECSCluster.load_services(self)

Retrieves the cluster's services.

    stored as the instance attribute `obj.services`

    :return: list<services>

nab3.service.ECSInstance(self, **kwargs)

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

nab3.service.ECSService(self, **kwargs)

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

nab3.service.ECSTask(self, **kwargs)

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

nab3.service.ElasticacheCluster(self, **kwargs)

boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elasticache.html#ElastiCache.Client.describe_cache_clusters

nab3.service.LaunchConfiguration(self, **kwargs)

boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.describe_launch_configurations

nab3.service.LoadBalancer(self, **kwargs)

boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.describe_load_balancers

nab3.service.LoadBalancerClassic(self, **kwargs)

boto3.amazonaws.com/v1/documentation/api/latest/reference/services/elbv2.html#ElasticLoadBalancingv2.Client.describe_load_balancers

nab3.service.Metric(self, **kwargs)

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

nab3.service.Pricing(self, **kwargs)

boto3.amazonaws.com/v1/documentation/api/latest/reference/services/pricing.html#Pricing.Client.get_products

nab3.service.SecurityGroup(self, **kwargs)

boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2.html#EC2.Client.describe_security_groups

nab3.utils

camel_to_kebab(str_obj: str) -> str

Convert a string from camel case to kebab case

camel_to_snake(str_obj: str) -> str

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:

snake_to_camelback(str_obj: str) -> str

Convert a string from snake_case to camelBack

snake_to_camelcap(str_obj: str) -> str

Convert a string from snake_case to CamelCap

nab3.mixin

nab3.mixin.AppAutoScaleMixin(self, **kwargs)

Mixin to provide app auto scale integrations for a service class

AppAutoScaleMixin.load_scaling_policies(self)

nab3.mixin.AutoScaleMixin(self, **kwargs)

AutoScaleMixin.load_scaling_policies(self)

nab3.mixin.MetricMixin(self, /, *args, **kwargs)

MetricMixin.get_available_metrics(self)

MetricMixin.get_metric_options(self)

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:

nab3.mixin.SecurityGroupMixin(self, **kwargs)

SecurityGroupMixin.load_accessible_resources(self)