0

I am trying to use this AWS Lambda to get results from an Amazon Athena query.

This is the Lambda function:

import boto3

# Query string to execute
query = 'SELECT DISTINCT awsaccountid, digeststarttime FROM smxtech.cloudtrail_digest'

# Database to execute the query against
DATABASE = 'xtech'

# Output location for query results
output='s3://xtech-destination/'

def lambda_handler(event, context):
    # Initiate the Boto3 Client
    client = boto3.client('athena')

    # Start the query execution
    response = client.start_query_execution(
        QueryString=query,
        QueryExecutionContext={
            'Database': DATABASE
        },
        ResultConfiguration={
            'OutputLocation': output
        }
    )

    # Return response after starting the query execution
    return response

I get an error:

{
  "QueryExecutionId": "6e9fa646-d8e2-4d11-b61f-579091f1a714",
  "ResponseMetadata": {
    "RequestId": "704e1467-3c8a-46c6-8cfa-04b8bf34bc6c",
    "HTTPStatusCode": 200,
    "HTTPHeaders": {
      "date": "Sun, 05 Feb 2023 02:13:18 GMT",
      "content-type": "application/x-amz-json-1.1",
      "content-length": "59",
      "connection": "keep-alive",
      "x-amzn-requestid": "704e1467-3c8a-46c6-8cfa-04b8bf34bc6c"
    },
    "RetryAttempts": 0
  }
}

Does anyone know how to resolve this error?

1 Answer 1

1

That is not an error. Your code is working perfectly.

The start_query_execution() API call starts execution of a query.

You can monitor the status of the query with get_query_execution(), which also returns the status of the query ('QUEUED'|'RUNNING'|'SUCCEEDED'|'FAILED'|'CANCELLED').

When the query has succeeded, you can retrieve the results with get_query_results().

Sign up to request clarification or add additional context in comments.

1 Comment

I figured it out after posting this. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.