示例#1
0
    def __init__(self,
                 s3_staging_dir=None,
                 region_name=None,
                 schema_name='default',
                 poll_interval=1,
                 encryption_option=None,
                 kms_key=None,
                 profile_name=None,
                 role_arn=None,
                 role_session_name='PyAthena-session-{0}'.format(
                     int(time.time())),
                 duration_seconds=3600,
                 converter=None,
                 formatter=None,
                 retry_exceptions=('ThrottlingException',
                                   'TooManyRequestsException'),
                 retry_attempt=5,
                 retry_multiplier=1,
                 retry_max_delay=1800,
                 retry_exponential_base=2,
                 cursor_class=Cursor,
                 **kwargs):
        if s3_staging_dir:
            self.s3_staging_dir = s3_staging_dir
        else:
            self.s3_staging_dir = os.getenv(self._ENV_S3_STAGING_DIR, None)
        assert self.s3_staging_dir, 'Required argument `s3_staging_dir` not found.'
        assert schema_name, 'Required argument `schema_name` not found.'
        self.region_name = region_name
        self.schema_name = schema_name
        self.poll_interval = poll_interval
        self.encryption_option = encryption_option
        self.kms_key = kms_key

        if role_arn:
            creds = self._assume_role(profile_name, region_name, role_arn,
                                      role_session_name, duration_seconds,
                                      **kwargs)
            profile_name = None
            kwargs.update({
                'aws_access_key_id': creds['AccessKeyId'],
                'aws_secret_access_key': creds['SecretAccessKey'],
                'aws_session_token': creds['SessionToken'],
            })
        self._session = Session(profile_name=profile_name, **kwargs)
        self._client = self._session.client('athena',
                                            region_name=region_name,
                                            **kwargs)

        self._converter = converter if converter else TypeConverter()
        self._formatter = formatter if formatter else ParameterFormatter()

        self.retry_exceptions = retry_exceptions
        self.retry_attempt = retry_attempt
        self.retry_multiplier = retry_multiplier
        self.retry_max_delay = retry_max_delay
        self.retry_exponential_base = retry_exponential_base

        self.cursor_class = cursor_class
        self._kwargs = kwargs
示例#2
0
    def __init__(self, s3_staging_dir=None, region_name=None, schema_name='default',
                 poll_interval=1, encryption_option=None, kms_key=None, profile_name=None,
                 converter=None, formatter=None,
                 retry_exceptions=('ThrottlingException', 'TooManyRequestsException'),
                 retry_attempt=5, retry_multiplier=1,
                 retry_max_delay=1800, retry_exponential_base=2,
                 cursor_class=Cursor, **kwargs):
        if s3_staging_dir:
            self.s3_staging_dir = s3_staging_dir
        else:
            self.s3_staging_dir = os.getenv(self._ENV_S3_STAGING_DIR, None)
        assert self.s3_staging_dir, 'Required argument `s3_staging_dir` not found.'
        assert schema_name, 'Required argument `schema_name` not found.'
        self.region_name = region_name
        self.schema_name = schema_name
        self.poll_interval = poll_interval
        self.encryption_option = encryption_option
        self.kms_key = kms_key

        if profile_name:
            session = Session(profile_name=profile_name, **kwargs)
            self._client = session.client('athena', region_name=region_name, **kwargs)
        else:
            self._client = boto3.client('athena', region_name=region_name, **kwargs)

        self._converter = converter if converter else TypeConverter()
        self._formatter = formatter if formatter else ParameterFormatter()

        self.retry_exceptions = retry_exceptions
        self.retry_attempt = retry_attempt
        self.retry_multiplier = retry_multiplier
        self.retry_max_delay = retry_max_delay
        self.retry_exponential_base = retry_exponential_base

        self.cursor_class = cursor_class
示例#3
0
    def __init__(self,
                 s3_staging_dir=None,
                 region_name=None,
                 schema_name='default',
                 work_group=None,
                 poll_interval=1,
                 encryption_option=None,
                 kms_key=None,
                 profile_name=None,
                 role_arn=None,
                 role_session_name='PyAthena-session-{0}'.format(
                     int(time.time())),
                 duration_seconds=3600,
                 converter=None,
                 formatter=None,
                 retry_config=None,
                 cursor_class=Cursor,
                 **kwargs):
        self._kwargs = kwargs
        if s3_staging_dir:
            self.s3_staging_dir = s3_staging_dir
        else:
            self.s3_staging_dir = os.getenv(self._ENV_S3_STAGING_DIR, None)
        assert self.s3_staging_dir, 'Required argument `s3_staging_dir` not found.'
        assert schema_name, 'Required argument `schema_name` not found.'
        self.region_name = region_name
        self.schema_name = schema_name
        self.work_group = work_group
        self.poll_interval = poll_interval
        self.encryption_option = encryption_option
        self.kms_key = kms_key

        if role_arn:
            creds = self._assume_role(profile_name, region_name, role_arn,
                                      role_session_name, duration_seconds)
            profile_name = None
            self._kwargs.update({
                'aws_access_key_id':
                creds['AccessKeyId'],
                'aws_secret_access_key':
                creds['SecretAccessKey'],
                'aws_session_token':
                creds['SessionToken'],
            })
        self._session = Session(profile_name=profile_name,
                                **self._session_kwargs)
        self._client = self._session.client('athena',
                                            region_name=region_name,
                                            **self._client_kwargs)
        self._converter = converter if converter else TypeConverter()
        self._formatter = formatter if formatter else ParameterFormatter()
        self._retry_config = retry_config if retry_config else RetryConfig()
        self.cursor_class = cursor_class