ars_def#

See ARSBase.

aws_resource_search.ars_def.validate_bsm(bsm: BotoSesManager)[source]#

validate the boto session manager. It has to have sts.get_caller_identity() permission because we need to get aws_account_id, and be able to get aws_region.

class aws_resource_search.ars_def.ARS(bsm: BotoSesManager, aws_console: aws_console_url.AWSConsole, searcher_finder: SearcherFinder = <factory>, dir_index: ~pathlib.Path = PosixPath('/home/docs/.aws_resource_search/.index'), dir_cache: ~pathlib.Path = PosixPath('/home/docs/.aws_resource_search/.cache'), cache: ~diskcache.core.Cache = None)[source]#

This class stands for “AWS Resource Search Base”, provides method to search AWS resources in Python.

In order to enable auto-complete in IDE, we need to explicitly declare per-resource-type searcher method in this class. However, we don’t want to maintain this wiring logics. Instead, we use Jinja template to generate, a code

Usage:

# import the singleton ARS object
>>> from aws_resource_search.api import ars
>>> ars.s3_bucket.search("my bucket")
[
    {
        "id": "my-bucket",
        "name": "my-bucket",
        ...
    },
    {
        ...
    },
]

This class is a singleton object that holds all context data such as boto_session_manager.BotoSesManager, aws_console_url.api.AwsConsole.

classmethod from_profile(profile: Optional[str] = Sentinel('NOTHING'))[source]#

Create a new ARSBase object by an AWS profile. If None, then use the default AWS profile.

get_searcher(resource_type: str) T_SEARCHER[source]#

Get corresponding aws_resource_search.res_lib.Searcher object by resource type.

clear_all_cache()[source]#

Clear all cache.

all_resource_types() List[str][source]#

Return all resource types.

is_valid_resource_type(resource_type: str) bool[source]#

Check if the resource type is supported.

set_profile(profile: Optional[str] = Sentinel('NOTHING'))[source]#

Set all boto session related attributes (bsm, aws_console, search_patterns) to use a new AWS profile.

Logics:

  1. Update the singleton bsm object by reset its cache and use a new AWS profile.

  2. Update the aws_console object to use the new bsm

  3. Since we updated the bsm, we also need to reset the searcher_finder

    cache to recreate all Searcher objects.