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.tomldependency 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.
optsandcontextare 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.optsandcontextare 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
nitems inlare truthy.