Athena workgroup result encryption settings need review

Verify Athena workgroup result encryption and which settings take precedence.

Description

For an Athena workgroup that stores query results in S3, choose the output location and encryption key at the workgroup level.

Potential impact

S3 encrypts new objects automatically. A client’s choice of bucket or key may still fall short of your requirements.

Remediation

Set the output location in result_configuration. If a customer managed key is required, set SSE_KMS and kms_key_arn in encryption_configuration. Use enforce_workgroup_configuration = true to enforce these settings. Check S3 and KMS access for existing automation, then run a test query and verify the result file’s location, key and read permissions.

Examples

Separate result-encryption configuration omitted

hcl
resource "aws_athena_workgroup" "analytics_wg" {
  name = "example"

  configuration {
    enforce_workgroup_configuration    = true
    publish_cloudwatch_metrics_enabled = true

    result_configuration {
      output_location = "s3://${aws_s3_bucket.example.bucket}/output/"
    }
  }
}

Result encryption key and enforcement configured

hcl
resource "aws_athena_workgroup" "analytics_wg" {
  name = "example"

  configuration {
    enforce_workgroup_configuration    = true
    publish_cloudwatch_metrics_enabled = true

    result_configuration {
      output_location = "s3://${aws_s3_bucket.example.bucket}/output/"

      encryption_configuration {
        encryption_option = "SSE_KMS"
        kms_key_arn       = aws_kms_key.example.arn
      }
    }
  }
}

Both workgroups enforce the specified output location. The second also sets the referenced KMS key. Check source data and existing result files separately.

References