0

My code to get Athena Query is

    self.athenaDataSource = "AwsCatalog"
    self.athenaDB = "prod_myapp_app"
    self.athenaResultBucket = "s3://s3-athena-prod-results/"
    

and here i show I create client and call .start_query_execution

    clientAthena = boto3.client('athena', region_name=awsRegion)
    athenaQueryExecResp = clientAthena.start_query_execution(
        QueryString=self.athenaQuery,
        QueryExecutionContext={ 'Database': self.athenaDB },
        ResultConfiguration={'OutputLocation': self.athenaResultBucket }
    )
    print("athenaQueryExecResp= "+str(athenaQueryExecResp))
    

I get this error

botocore.exceptions.ClientError: An error occurred (UnrecognizedClientException) when calling the StartQueryExecution operation: The security token included in the request is invalid.

The thing is it means I am not passing security which si correct but how do I pass the credentials. I checked https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/athena.html#Athena.Client.start_query_execution it never mentions anythign about passing credentials security access and token

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Ghost
  • 549
  • 8
  • 29
  • Are you running locally or in aws lambda? – jellycsc Aug 04 '20 at 22:03
  • 1
    The error message is suggesting that your credentials are stored with an Access Key, Secret Key and Security Token. This third entity is used when using _temporary credentials_, such as those returned by an `AssumeRole` command. If you are running this code on your own computer, check the contents of the `~/.aws/credentials` file to see whether a `aws_security_token` is defined. If it is, it has a bad value. – John Rotenstein Aug 05 '20 at 07:38
  • Interestingly, sounds very similar to: [Getting Error “The security token included in the request is invalid” UnrecognizedClientException when calling the StartQueryExecution operation](https://stackoverflow.com/q/63262311/174777) – John Rotenstein Aug 05 '20 at 09:46
  • Thanks that was my problem I have resolved it . – Ghost Aug 05 '20 at 15:27
  • worked for me after setting "AWS_SESSION_TOKEN" env variable along with AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY - thanks @JohnRotenstein – Sharath BJ Oct 15 '20 at 13:36

0 Answers0