4

I am trying to execute athena query using c# athena driver.

Amazon.Athena.Model.ResultConfiguration resultConfig = new Amazon.Athena.Model.ResultConfiguration();
resultConfig.OutputLocation = "https://s3.us-east-2.amazonaws.com/testbucket/one/2018-02-06/";
//other inputs i have tried
//"s3://testbucket/one/2018-02-06/"
//testbucket

//Populate the request object
                Amazon.Athena.Model.StartQueryExecutionRequest queryExec = new Amazon.Athena.Model.StartQueryExecutionRequest();
                queryExec.QueryString = query.QueryString;
                queryExec.QueryExecutionContext = queryExecutionContext;
                queryExec.ResultConfiguration = resultConfig;

StartQueryExecutionResponse athenaResponse = athenaClient.StartQueryExecution(queryExec);//throws exception

Exception for different cases:

  1. outputLocation is not a valid S3 path. Provided https://s3.us-east-2.amazonaws.com/testbucket/one/2018-02-06/

  2. Unable to verify/create output bucket testbucket. Provided s3://testbucket/one/2018-02-06/

  3. Unable to verify/create output bucket testbucket. Provided testbucket

Can someone help me out with the right s3 format?

Thanks in advance.

Community
  • 1
  • 1
kaarthick raman
  • 41
  • 1
  • 1
  • 3

2 Answers2

6

The output location needs to be in the following format:

s3://{bucketname}/{path}

In your case this would lead to the following location:

resultConfig.OutputLocation = "s3://testbucket/one/2018-02-06/";
jens walter
  • 13,269
  • 2
  • 56
  • 54
1
Amazon.Athena.AmazonAthenaClient _client = new Amazon.Athena.AmazonAthenaClient(AwsAccessKeyId, AwsSecretAccessKey, EndPoint);
                Amazon.Athena.Model.ResultConfiguration resultConfig = new Amazon.Athena.Model.ResultConfiguration();
                resultConfig.OutputLocation = "s3://"+BucketName+"/key1/";                
                string query = "SELECT * FROM copalanadev.logs";
                //Populate the request object
                Amazon.Athena.Model.StartQueryExecutionRequest queryExec = new Amazon.Athena.Model.StartQueryExecutionRequest();
                queryExec.QueryString = query;
                //queryExec.QueryExecutionContext = queryExecutionContext;
                queryExec.ResultConfiguration = resultConfig;

            StartQueryExecutionResponse athenaResponse = _client.StartQueryExecution(queryExec);//throws exception
Fredrik Widerberg
  • 3,068
  • 10
  • 30
  • 42
Vinod
  • 11
  • 3