Exemplo n.º 1
0
def paginate(
        client: client, method: str,
        **kwargs: Dict[str, Any]) -> Generator[Dict[str, Any], None, None]:
    """
    Iterates over the pages of an API operation results.

    Paginators act as an abstraction over the process of iterating over an entire result set of
    a truncated API operation. Yields an iterable with the response obtained from applying
    `method`.

    Parameters
    ----------
    method : str
        Name of the API operation request.
    kwargs : Dict[str, Any]
        Additional arguments for the specified method.

    Yields
    ------
    Generator[Dict[str, Any], None, None]
        Responses dictionaries of the `method`.

    Notes
    -----
    More information on the use of AWS paginators: [1].

    References
    ----------
    [1] :
    https://boto3.amazonaws.com/v1/documentation/api/latest/guide/paginators.html

    """
    paginator = client.get_paginator(operation_name=method)
    for page in paginator.paginate(**kwargs):
        yield page
def get_cluster_and_container_instance_arn(client: botocore.client.BaseClient,
                                           instance_id: str) -> (str, str):
    list_clusters_paginator = client.get_paginator("list_clusters")
    for page in list_clusters_paginator.paginate():
        for cluster in page["clusterArns"]:
            list_container_instances_paginator = client.get_paginator(
                "list_container_instances")
            for instance in list_container_instances_paginator.paginate(
                    cluster=cluster, status="ACTIVE"):
                if instance.get("containerInstanceArns"):
                    describe_container_instances_response = client.describe_container_instances(
                        cluster=cluster,
                        containerInstances=instance["containerInstanceArns"])
                    for container_instance in describe_container_instances_response[
                            "containerInstances"]:
                        if instance_id in container_instance["ec2InstanceId"]:
                            return cluster, container_instance[
                                "containerInstanceArn"]
    return None, None
Exemplo n.º 3
0
def get_hosted_zone_by_name(client, zone_name):
    """Get the zone id of an existing zone by name.

    Args:
        client (:class:`botocore.client.Route53`): The connection used to
            interact with Route53's API.
        zone_name (string): The name of the DNS hosted zone to create.

    Returns:
        string: The Id of the Hosted Zone.
    """
    p = client.get_paginator("list_hosted_zones")

    for i in p.paginate():
        for zone in i["HostedZones"]:
            if zone["Name"] == zone_name:
                return parse_zone_id(zone["Id"])
    return None
Exemplo n.º 4
0
def get_hosted_zone_by_name(client, zone_name):
    """Get the zone id of an existing zone by name.

    Args:
        client (:class:`botocore.client.Route53`): The connection used to
            interact with Route53's API.
        zone_name (string): The name of the DNS hosted zone to create.

    Returns:
        string: The Id of the Hosted Zone.
    """
    p = client.get_paginator("list_hosted_zones")

    for i in p.paginate():
        for zone in i["HostedZones"]:
            if zone["Name"] == zone_name:
                return parse_zone_id(zone["Id"])
    return None
Exemplo n.º 5
0
def get_hosted_zone_by_name(client: Route53Client,
                            zone_name: str) -> Optional[str]:
    """Get the zone id of an existing zone by name.

    Args:
        client: The connection used to interact with Route53's API.
        zone_name: The name of the DNS hosted zone to create.

    Returns:
        The Id of the Hosted Zone.

    """
    paginator = client.get_paginator("list_hosted_zones")

    for page in paginator.paginate():
        for zone in page["HostedZones"]:
            if zone["Name"] == zone_name:
                return parse_zone_id(zone["Id"])
    return None