Skip to content Skip to sidebar Skip to footer

Lambda Python Request Athena Error Outputlocation

I'm working with AWS Lambda and I would like to make a simple query in athena and store my data in an s3. My code : import boto3 def lambda_handler(event, context): query_1 =

Solution 1:

ClientRequestToken (string) -- A unique case-sensitive string used to ensure the request to create the query is idempotent (executes only once). If another StartQueryExecution request is received, the same response is returned and another query is not created. If a parameter has changed, for example, the QueryString , an error is returned. [Boto3 Docs]

This field is autopopulated if not provided.

If you are providing a string value for ClientRequestToken, ensure it is within length limits from 32 to 128.

Solution 2:

Per @Tomalak's point ClientRequestToken is a string. However, per the documentation I just linked, you don't need it anyway when using the SDK.

This token is listed as not required because AWS SDKs (for example the AWS SDK for Java) auto-generate the token for users. If you are not using the AWS SDK or the AWS CLI, you must provide this token or the action will fail.

So, I would refactor as such:

import boto3


deflambda_handler(event, context):
    query_1 = "SELECT * FROM some_database.some_table limit 5;"
    database = "some_database"
    s3_output = "s3://some_bucket/some_tag/"

    client = boto3.client('athena')

    response = client.start_query_execution(QueryString = query_1,
                                        QueryExecutionContext={
                                            'Database': database
                                        },
                                        ResultConfiguration={
                                            'OutputLocation': s3_output
                                        }
                                        )
    return response

Post a Comment for "Lambda Python Request Athena Error Outputlocation"