Monday, 12 June 2023

unit testing aws athena query

import awswrangler as wr

def assume_role_and_query_athena(role_arn, query):
    # Assume the IAM role
    sts_client = boto3.client('sts')
    assumed_role = sts_client.assume_role(
        RoleArn=role_arn,
        RoleSessionName='AssumedRoleSession'
    )
    
    # Extract the temporary credentials from the AssumeRole response
    credentials = assumed_role['Credentials']
    access_key = credentials['AccessKeyId']
    secret_key = credentials['SecretAccessKey']
    session_token = credentials['SessionToken']
    
    # Use the temporary credentials to execute the query in Athena
    wr.athena.connect(
        access_key=access_key,
        secret_key=secret_key,
        session_token=session_token,
        region='us-east-1'  # Replace with your desired AWS region
    )
    df = wr.athena.read_sql_query(query)
    
    return df

My question is how do we unit test the above code. I don't feel like there is much to unit test for. The core test needed is probably about being able to establish the connection which cannot really be unit tested.



from unit testing aws athena query

No comments:

Post a Comment