def ex42(stage, ex_query): out = athenaQueryExecutor.executeQuery(ex_query, stage) rs = responseformat(out=out) if (rs['status'] == 'SUCCEEDED'): out = athenaQueryExecutor.processresultset(rs['queryid']) print(out) if len(out) < 1: rs['status'] = 'FAILED' rs['message'] = 'Zero Rows returned,perhaps, relauch the cf to fix the issue' else: if (len(out) >= 2): try: validate(out[1], '%Y-%m-%d %H:%M:%S.%f') except: rs['status'] = 'FAILED' rs['message'] = out return rs rs['message'] = out[1] else: rs['status'] = 'FAILED' rs['message'] = out return rs else: return rs
def ex32(stage, ex_query): accountid = boto3.client('sts').get_caller_identity().get('Account') arn = 'arn:aws:iam::{}:role/Athena_Exercise_lab32_Role'.format(accountid) session = role_arn_to_session(RoleArn=arn, RoleSessionName='lab_32') client = session.client('athena') out = athenaQueryExecutor.executeQuery(ex_query, stage, client) return responseformat(out=out)
def ex13(stage, ex_query): out = athenaQueryExecutor.executeQuery(ex_query, stage) rs = responseformat(out=out) if (rs['status'] == 'SUCCEEDED'): out = athenaQueryExecutor.processresultset(rs['queryid']) if out[1] == '': rs['status'] = 'FAILED' rs['message'] = 'TimeStamp Column is Empty' return rs else: return rs
def ex15(stage, ex_query): out = athenaQueryExecutor.executeQuery(ex_query, stage) rs = responseformat(out=out) if (rs['status'] == 'SUCCEEDED'): out = athenaQueryExecutor.processresultset(rs['queryid']) print(out) if len(out) < 2: rs['status'] = 'FAILED' rs['message'] = 'Zero Rows returned' else: rs['message'] = out[1] return rs else: return rs
def ex41(stage, ex_query): out = athenaQueryExecutor.executeQuery(ex_query, stage) rs = responseformat(out=out) if (rs['status'] == 'SUCCEEDED'): out = athenaQueryExecutor.processresultset(rs['queryid']) print(out) if len(out) < 1: rs['status'] = 'FAILED' rs['message'] = 'Zero Rows returned,perhaps, relauch the cf to fix the issue' else: if (len(out[1].split(',')) == 2): rs['message'] = athenaQueryExecutor.tableConstruct(out) else: rs['status'] = 'FAILED' rs['message'] = out return rs else: return rs
def ex11(stage, ex_query): out = athenaQueryExecutor.executeQuery(ex_query, stage) return responseformat(out=out)
def ex2X(stage, ex_query): out = athenaQueryExecutor.executeQuery(ex_query, stage) if ('status' in out.keys()): return out return responseformat(out=out)