I am trying to coonect s3 using Athena to perform some SQL operatin for the data stored on s3.

Here is my code

import boto3
from sqlalchemy import create_engine

# Configure AWS credentials

boto3.setup_default_session(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)
region = 'us-east-1'
# Connect to Amazon Athena

connathena = f"athena.{region}.amazonaws.com"
portathena = '443'  # Update if the port is different
schemaathena = glue_db_name  # from user-defined params
s3stagingathena = f's3://{glue_databucket_name}/athenaresults/'  # from CloudFormation parameters

wkgrpathena = 'primary'  # Update if the workgroup is different

# Create the Athena connection string

connection_string = f"awsathena+rest://@{connathena}:{portathena}/{schemaathena}?s3_staging_dir={s3stagingathena}/&work_group={wkgrpathena}"

# Create the Athena SQLAlchemy engine
engine_athena = create_engine(connection_string, echo=True)

dbathena = SQLDatabase(engine_athena)
gdc = [schemaathena]

I am getting an error at line dbathena = SQLDatabase(engine_athena)

error " Nocredentialserror. botocore.exceptions.nocredentialserror : unable to locate credentials 

OperationalError: Unable to locate credentials

I already tried adding my credentials. Earlier boto3.setup_default_session(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)

was not present, Added it but still error is still there

0

There are 0 best solutions below