saltext.boto3.utils.boto3mod

Boto3 Common Utils

Common helpers for boto3-based execution and state modules.

Execution/state modules call these helpers directly, passing their own __opts__ and __context__:

from saltext.boto3.utils import boto3mod


def __virtual__():
    return "my_service"


def describe():
    conn = boto3mod.get_connection(
        "ec2", opts=__opts__, context=__context__, profile="myprofile"
    )
    instance_id = boto3mod.cache_id(
        "ec2", "myinstance", opts=__opts__, context=__context__
    )

Added in version 1.0.0.

saltext.boto3.utils.boto3mod.__virtual__()[source]

Only load if boto3 is available. Minimum version is enforced via the project’s pyproject.toml dependency declaration.

saltext.boto3.utils.boto3mod.cache_id(service, name, *, opts, context, sub_resource=None, resource_id=None, invalidate=False, region=None, key=None, keyid=None, profile=None)[source]

Cache, invalidate, or retrieve an AWS resource id keyed by name.

opts and context are required; pass __opts__ and __context__ from the calling module.

boto3mod.cache_id(
    "ec2",
    "myinstance",
    opts=__opts__,
    context=__context__,
    resource_id="i-a1b2c3",
    profile="custom_profile",
)
saltext.boto3.utils.boto3mod.get_connection(service, *, opts, context, module=None, region=None, key=None, keyid=None, profile=None)[source]

Return a boto3 client for the given service, caching it in context.

opts and context are required; pass __opts__ and __context__ from the calling module.

conn = boto3mod.get_connection(
    "ec2",
    opts=__opts__,
    context=__context__,
    profile="custom_profile",
)
saltext.boto3.utils.boto3mod.get_region(service, region, profile, *, opts)[source]

Return the resolved region for a service based on the supplied region/profile and the calling module’s opts.

saltext.boto3.utils.boto3mod.get_error(e)[source]

Best-effort extraction of an error message from a boto/botocore exception.

saltext.boto3.utils.boto3mod.exactly_n(l, n=1)[source]

Return True when exactly n items in l are truthy.

saltext.boto3.utils.boto3mod.paged_call(function, *args, **kwargs)[source]

Yield successive pages from a boto3 API call that may paginate via NextMarker / Marker (override with marker_flag and marker_arg kwargs).

saltext.boto3.utils.boto3mod.json_objs_equal(left, right)[source]

Compare two parsed JSON objects, ignoring ordering inside containers.