☁️ 6.1 Athena

A MATLAB client for the Amazon Athena service. Use it to run SQL queries on data in Amazon S3 via Athena’s serverless engine.

athena = aws.athena.Client('region', 'us-east-1');

Note

Athena queries require a valid S3 output location and access to a database in your AWS Glue Data Catalog.

🔧 6.1.1 List of Available Methods

🧩 6.1.2 Examples

Start a simple query:

queryString = "SELECT 1 AS test_col";
rc = aws.athena.model.ResultConfiguration(outputLocation = "s3://your-bucket/results/");
qc = aws.athena.model.QueryExecutionContext(database = "your-database");

resp = athena.startQueryExecution( ...
    queryString = queryString, ...
    queryExecutionContext = qc, ...
    resultConfiguration = rc);

disp(resp.queryExecutionId);

Wait for completion:

maxWait = 60;
tStart = tic;
while true
    statusResp = athena.getQueryExecution(queryExecutionId = resp.queryExecutionId);
    state = string(statusResp.status.state);
    if state == "SUCCEEDED"
        break;
    elseif state == "FAILED" || state == "CANCELLED"
        error("Query failed or was cancelled: %s", state);
    elseif toc(tStart) > maxWait
        error("Query timed out after %d seconds", maxWait);
    end
    pause(2);
end

Fetch results:

resultResp = athena.getQueryResults(queryExecutionId = resp.queryExecutionId);
disp(resultResp.resultSet);

Stop a running query:

stopResp = athena.stopQueryExecution(queryExecutionId = resp.queryExecutionId);
disp(stopResp.statusCode);

📘 6.1.3 Method Reference (Summary)

🔸 startQueryExecution

response = athena.startQueryExecution( ...
    queryString = "<SQL>", ...
    queryExecutionContext = <QueryExecutionContext>, ...
    resultConfiguration = <ResultConfiguration>);
  • Returns: aws.athena.model.StartQueryExecutionResponse (includes queryExecutionId)

🔸 getQueryExecution

statusResp = athena.getQueryExecution(queryExecutionId = "<id>");
  • Returns: aws.athena.model.GetQueryExecutionResponse

🔸 getQueryResults

resultResp = athena.getQueryResults(queryExecutionId = "<id>", maxResults = <int>);
  • Returns: aws.athena.model.GetQueryResultsResponse

🔸 stopQueryExecution

stopResp = athena.stopQueryExecution(queryExecutionId = "<id>");
  • Returns: aws.athena.model.StopQueryExecutionResponse