Skip to content

(aws-stepfunctions-tasks): Athena QueryExecutionContext on StartQueryExecution is superfluous and leads to error #16133

@LukvonStrom

Description

@LukvonStrom

The following error appears in my stepfunction console:

{
  "resourceType": "athena",
  "resource": "startQueryExecution.sync",
  "error": "Athena.InvalidRequestException",
  "cause": "Both queryExecutionContext.catalog and queryExecutionContext.database are null or empty (Service: AmazonAthena; Status Code: 400; Error Code: InvalidRequestException; Request ID: [Censored]; Proxy: null)"
}

Reproduction Steps

I use the following code to start the Athena Query execution:

new AthenaStartQueryExecution(this,"stepfunction-start-query", {
            queryString: `[Some Query]`,
            integrationPattern: IntegrationPattern.RUN_JOB,
            resultConfiguration: {
                outputLocation: {
                    bucketName: bucket.bucketName,
                    objectKey: `States.Format('athena/{}/{}', $$.Execution.StartTime, $$.State.EnteredTime)`,
                },
            }
        })

apart from the not really working object Key (which is a problem I aim to resolve later on), the code seems to insert a queryExecutionContext in the generated State Machine.

I retrieved the following snippet from the stepfunction console:

"stepfunction-start-query": {
      "Type": "Task",
      "Resource": "arn:aws:states:::athena:startQueryExecution.sync",
      "Parameters": {
        "QueryString": "[Some Query]",
        "QueryExecutionContext": {},
        "ResultConfiguration": {
          "OutputLocation": "s3://[Bucket]/States.Format('athena/{}/{}', $$.Execution.StartTime, $$.State.EnteredTime)/"
        }
      }
    }

What did you expect to happen?

As queryExecutionContext is marked as optional in https://github.com/aws/aws-cdk/blob/v1.119.0/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/start-query-execution.ts#L30 and the comment states @default - No query execution context I did not expect CDK to generate any QueryExecutionContext.

What actually happened?

In line https://github.com/aws/aws-cdk/blob/v1.119.0/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/start-query-execution.ts#L192 one can see, that only the values are being toggled, but not the whole QueryExecutionContext which is the source of the error.

Environment

  • CDK CLI Version : Current main branch

Other

To fix this, I suggest on dymamically inserting the QueryExecutionContext when its defined (it cannot be null either) like this:

protected _renderTask(): any {

    let renderedObject = {
        Resource: integrationResourceArn('athena', 'startQueryExecution', this.integrationPattern),
        Parameters: sfn.FieldUtils.renderObject({
            QueryString: this.props.queryString,
            ClientRequestToken: this.props.clientRequestToken,
            ResultConfiguration: {
                EncryptionConfiguration: this.renderEncryption(),
            },
            WorkGroup: this.props.workGroup,
        }),
    }


    if (this.props.resultConfiguration?.outputLocation) {
        renderedObject.ResultConfiguration.OutputLocation = `s3://${this.props.resultConfiguration?.outputLocation?.bucketName}/${this.props.resultConfiguration?.outputLocation?.objectKey}/`,
    }

    if (this.props?.queryExecutionContext) {
        renderedObject.QueryExecutionContext = {
            Catalog: this.props.queryExecutionContext?.catalogName,
            Database: this.props.queryExecutionContext?.databaseName,
        }
    }


    return renderedObject;
}

This is 🐛 Bug Report

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-athenaRelated to AWS AthenabugThis issue is a bug.effort/mediumMedium work item – several days of effortp1

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions