查询雅典娜时InvalidSignatureException

时间:2020-04-21 20:09:09

标签: docker

我有一个应用程序,可以从python在雅典娜中运行查询。

def execute(self):
        session = boto3.Session(profile_name='prod')
        client = session.client('athena')
        s3_client = session.client('s3')
        response = client.start_query_execution(
            QueryString=self._query,
            QueryExecutionContext={
                'Database': self.database},
            ResultConfiguration={'OutputLocation': 's3://{0}/{1}/'.format(
                BUCKET, PATH)},
            WorkGroup=self.workgroup)
        ids = response['QueryExecutionId']
        filename = '{0}/{1}.{2}'.format(PATH, ids, self.extension)
        local_name = '{0}.{1}'.format(ids, self.extension)
        success = False
        time.sleep(2)
        tries = 0
        while success is False:
            status = client.get_query_execution(QueryExecutionId=ids)
            state = status['QueryExecution']['Status']['State']
            if state in {'RUNNING', 'QUEUED'}:
                time.sleep(1)
            elif state in {'FAILED', 'CANCELLED'}:
                LOGGER.error('QUERY FAILED')
                raise Exception
            else:
                try:
                    s3_client.download_file(BUCKET, filename, local_name)
                except Exception as err:
                    LOGGER.error(err)
                if self.extension == 'csv':
                    data = pd.read_csv(local_name)
                else:
                    data = open(local_name, 'r').readlines()
                os.remove(local_name)
                return data

            tries += 1
            if tries > 1000:
                raise TimeoutError

以上功能执行查询部分。当我从本地环境运行时,它可以正常运行。我已经将应用程序泊坞窗了。当我在docker内部运行它时,它给了我以下错误:

botocore.exceptions.ClientError: An error occurred (InvalidSignatureException) when calling the StartQueryExecution operation: Signature expired: 20200421T195604Z is now earlier than 20200421T195713Z (20200421T200213Z - 5 min.)

任何人都可以领导这种情况。

0 个答案:

没有答案