How to use the boto3.__version__ function in boto3

To help you get started, we’ve selected a few boto3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github saltstack / salt / tests / unit / modules / test_boto_cognitoidentity.py View on Github external
def _has_required_boto():
    '''
    Returns True/False boolean depending on if Boto is installed and correct
    version.
    '''
    if not HAS_BOTO:
        return False
    elif LooseVersion(boto3.__version__) < LooseVersion(required_boto3_version):
        return False
    else:
        return True
github turnerlabs / antiope / aws-inventory / lambda / inventory-ecs.py View on Github external
cluster_item['tags']                       = parse_ecs_tags(cluster['tags'])
                    cluster_item['supplementaryConfiguration']     = {}
                    cluster_item['resourceId']                     = "{}-{}".format(cluster['clusterName'], target_account.account_id)
                    cluster_item['resourceName']                   = cluster['clusterName']
                    cluster_item['ARN']                            = cluster['clusterArn']
                    cluster_item['errors']                         = {}
                    save_resource_to_s3(CLUSTER_RESOURCE_PATH, cluster_item['resourceId'], cluster_item)

                    for task_arn in list_tasks(ecs_client, cluster_arn):

                        # Lambda's boto doesn't yet support this API Feature
                        try:
                            task = ecs_client.describe_tasks(cluster=cluster_arn, tasks=[task_arn], include=['TAGS'])['tasks'][0]
                        except ParamValidationError as e:
                            import botocore
                            logger.error(f"Unable to fetch Task Tags - Lambda Boto3 doesn't support yet. Boto3: {boto3.__version__} botocore: {botocore.__version__}")
                            task = ecs_client.describe_tasks(cluster=cluster_arn, tasks=[task_arn])['tasks'][0]

                        task_item = {}
                        task_item['awsAccountId']                   = target_account.account_id
                        task_item['awsAccountName']                 = target_account.account_name
                        task_item['resourceType']                   = "AWS::ECS::Task"
                        task_item['source']                         = "Antiope"
                        task_item['configurationItemCaptureTime']   = str(datetime.datetime.now())
                        task_item['awsRegion']                      = r
                        task_item['configuration']                  = task
                        if 'tags' in task:
                            task_item['tags']                       = parse_ecs_tags(task['tags'])
                        task_item['supplementaryConfiguration']     = {}
                        task_item['resourceId']                     = "{}-{}".format(task['taskDefinitionArn'].split('/')[-1], target_account.account_id)
                        task_item['resourceName']                   = task['taskDefinitionArn'].split('/')[-1]
                        task_item['ARN']                            = task['taskArn']
github aws-samples / amazon-textract-comprehend-OCRimage-search-and-analyze / lambda / comprehend.py View on Github external
import io
from io import BytesIO
import sys
from trp import Document

try:
    from urllib.parse import unquote_plus
except ImportError:
     from urllib import unquote_plus


print('setting up boto3')

root = os.environ["LAMBDA_TASK_ROOT"]
sys.path.insert(0, root)
print(boto3.__version__)
print('core path setup')
s3 = boto3.resource('s3')
s3client = boto3.client('s3')

host= os.environ['esDomain']
print("ES DOMAIN IS..........")
region=os.environ['AWS_REGION']

service = 'es'
credentials = boto3.Session().get_credentials()

def connectES():
 print ('Connecting to the ES Endpoint {0}')
 awsauth = AWS4Auth(credentials.access_key, 
 credentials.secret_key, 
 region, service,
github JohannesEbke / aws_list_all / aws_list_all / introspection.py View on Github external
def get_endpoint_hosts():
    print('Extracting endpoint list from boto3 version {} ...'.format(boto3.__version__))
    EC2_REGIONS = set(boto3.Session().get_available_regions('ec2'))
    S3_REGIONS = set(boto3.Session().get_available_regions('s3'))
    ALL_REGIONS = sorted(EC2_REGIONS | S3_REGIONS)
    ALL_SERVICES = get_services()
    result = {
        service:
        {region: boto3.Session(region_name=region).client(service).meta.endpoint_url
         for region in ALL_REGIONS}
        for service in ALL_SERVICES
    }
    print('...done.')
    return result
github epam / cloud-pipeline / workflows / pipe-common / pipeline / autoscaling / awsprovider.py View on Github external
def __init__(self, cloud_region, num_rep=10):
        self.cloud_region = cloud_region
        boto3.setup_default_session(region_name=cloud_region)

        # Hacking max max_attempts to get rid of
        # "An error occurred (RequestLimitExceeded) when calling the ... operation (reached max retries: 4)"
        # Official solution shall be provided with https://github.com/boto/botocore/pull/1260, waiting for release
        # This is applied to the old versions of botocore
        boto3_version = LooseVersion(boto3.__version__)
        boto3_version_retries = LooseVersion("1.7")
        utils.pipe_log('Using boto3 version {}'.format(boto3.__version__))

        self.ec2 = None
        if boto3_version < boto3_version_retries:
            try:
                self.ec2 = boto3.client('ec2')
                if hasattr(self.ec2.meta.events, "_unique_id_handlers"):
                    self.ec2.meta.events._unique_id_handlers['retry-config-ec2']['handler']._checker.__dict__['_max_attempts'] = BOTO3_RETRY_COUNT
            except Exception as inner_exception:
                utils.pipe_log('Unable to modify retry config:\n{}'.format(str(inner_exception)))
        else:
            self.ec2 = boto3.client('ec2', config=Config(retries={'max_attempts': BOTO3_RETRY_COUNT}))
github nccgroup / ScoutSuite / opinel / utils / globals.py View on Github external
requirements_file = os.path.join(script_dir, 'requirements.txt')
    with open(requirements_file, 'rt') as f:
        for requirement in f.readlines():
            opinel_requirements = re_opinel.match(requirement)
            if opinel_requirements:
                opinel_requirements = opinel_requirements.groups()
                opinel_min_version = opinel_requirements[0]
                opinel_max_version = opinel_requirements[1]
            boto3_requirements = re_boto3.match(requirement)
            if boto3_requirements:
                boto3_requirements = boto3_requirements.groups()
                boto3_min_version = boto3_requirements[0]
                boto3_max_version = boto3_requirements[1]
    if not check_versions(opinel_min_version, OPINEL_VERSION, opinel_max_version, 'opinel'):
        return False
    if not check_versions(boto3_min_version, boto3.__version__, boto3_max_version, 'boto3'):
        return False
    return True
github jorgebastida / aws2fa / aws2fa / bin.py View on Github external
import platform
        import traceback
        options = vars(options)
        options['aws_access_key_id'] = 'SENSITIVE'
        options['aws_secret_access_key'] = 'SENSITIVE'
        options['aws_session_token'] = 'SENSITIVE'
        options['aws_profile'] = 'SENSITIVE'
        sys.stderr.write("\n")
        sys.stderr.write("=" * 80)
        sys.stderr.write("\nYou've found a bug! Please, raise an issue attaching the following traceback\n")
        sys.stderr.write("https://github.com/jorgebastida/aws2fa/issues/new\n")
        sys.stderr.write("-" * 80)
        sys.stderr.write("\n")
        sys.stderr.write("Version: {0}\n".format(__version__))
        sys.stderr.write("Python: {0}\n".format(sys.version))
        sys.stderr.write("boto3 version: {0}\n".format(boto3.__version__))
        sys.stderr.write("Platform: {0}\n".format(platform.platform()))
        sys.stderr.write("Config: {0}\n".format(options))
        sys.stderr.write("Args: {0}\n\n".format(sys.argv))
        sys.stderr.write(traceback.format_exc())
        sys.stderr.write("=" * 80)
        sys.stderr.write("\n")
        return 1

    return 0
github saltstack / salt / salt / modules / boto_iot.py View on Github external
def __virtual__():
    '''
    Only load if boto libraries exist and if boto libraries are greater than
    a given version.
    '''
    required_boto3_version = '1.2.1'
    required_botocore_version = '1.4.41'
    # the boto_lambda execution module relies on the connect_to_region() method
    # which was added in boto 2.8.0
    # https://github.com/boto/boto/commit/33ac26b416fbb48a60602542b4ce15dcc7029f12
    if not HAS_BOTO:
        return (False, 'The boto_iot module could not be loaded: '
                'boto libraries not found')
    elif _LooseVersion(boto3.__version__) < _LooseVersion(required_boto3_version):
        return (False, 'The boto_iot module could not be loaded: '
                'boto3 version {0} or later must be installed.'.format(required_boto3_version))
    elif _LooseVersion(found_botocore_version) < _LooseVersion(required_botocore_version):
        return (False, 'The boto_iot module could not be loaded: '
                'botocore version {0} or later must be installed.'.format(required_botocore_version))
    else:
        return True
github boto / boto3 / boto3 / session.py View on Github external
if botocore_session is not None:
            self._session = botocore_session
        else:
            # Create a new default session
            self._session = botocore.session.get_session()

        # Setup custom user-agent string if it isn't already customized
        if self._session.user_agent_name == 'Botocore':
            botocore_info = 'Botocore/{0}'.format(
                self._session.user_agent_version)
            if self._session.user_agent_extra:
                self._session.user_agent_extra += ' ' + botocore_info
            else:
                self._session.user_agent_extra = botocore_info
            self._session.user_agent_name = 'Boto3'
            self._session.user_agent_version = boto3.__version__

        if profile_name is not None:
            self._session.set_config_variable('profile', profile_name)

        if aws_access_key_id or aws_secret_access_key or aws_session_token:
            self._session.set_credentials(
                aws_access_key_id, aws_secret_access_key, aws_session_token)

        if region_name is not None:
            self._session.set_config_variable('region', region_name)

        self.resource_factory = ResourceFactory(
            self._session.get_component('event_emitter'))
        self._setup_loader()
        self._register_default_handlers()
github jorgebastida / awslogs / awslogs / bin.py View on Github external
import re
        import traceback
        options = vars(options)
        options['aws_access_key_id'] = 'SENSITIVE'
        options['aws_secret_access_key'] = 'SENSITIVE'
        options['aws_session_token'] = 'SENSITIVE'
        options['aws_profile'] = 'SENSITIVE'
        sys.stderr.write("\n")
        sys.stderr.write("\nYou've found a bug! Please, raise an issue attaching the following traceback\n")
        sys.stderr.write("https://github.com/jorgebastida/awslogs/issues/new\n")
        sys.stderr.write("\n")

        issue_info = "\n".join((
            "Version:       {0}".format(__version__),
            "Python:        {0}".format(sys.version),
            "boto3 version: {0}".format(boto3.__version__),
            "Platform:      {0}".format(platform.platform()),
            "Args:          {0}".format(sys.argv),
            # use pformat for ordering and nice rendering
            "Config: {0}".format(pprint.pformat(options)),
            "",
            traceback.format_exc(),
        ))
        # use enough backticks to properly escape the issue_info pre-formatted block
        try:
            backtick_count = 1 + max(
                (len(match.group()) for match in re.finditer(r"`{3,}", issue_info)),
            )
        except ValueError:
            # only needed for python 2 as later have a `default` parameter to the max function
            backtick_count = 3
        backticks = "`" * backtick_count + "\n"