How do I resolve the "Unable to verify/create output bucket" error in Amazon Athena?

Last updated: 2021-02-09

When I run Amazon Athena queries in SQL Workbench/J, in AWS Lambda, or with an AWS SDK, I get the error: "Unable to verify/create output bucket."

Short description

Here are some common causes of this error:

  • The Amazon Simple Storage Service (Amazon S3) bucket that you specified for the query result location doesn't exist.
  • The AWS Identity and Access Management (IAM) policy for the user or role that is running the query doesn't have the required Amazon S3 permissions, such as s3:GetBucketLocation.

Resolution

If you manually set the query result location, you must confirm that the S3 bucket exists. Then, check the IAM policy for the user or role that is running the query:

  • Confirm that the permissions in the following example policy are allowed.
  • Be sure that the IAM policy does not contain a Deny statement that uses aws:SourceIp or aws:SourceVpc to restrict S3 permissions.

Note: The s3:CreateBucket permission isn't required if the bucket already exists. If you manually set the query result location, then don't include arn:aws:s3:::aws-athena-query-results-* in the policy. The policy must include arn:aws:s3:::query-results-custom-bucket and arn:aws:s3:::query-results-custom-bucket/* only if you manually set the query result location.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetBucketLocation",
                "s3:GetObject",
                "s3:ListBucket",
                "s3:ListBucketMultipartUploads",
                "s3:ListMultipartUploadParts",
                "s3:AbortMultipartUpload",
                "s3:CreateBucket",
                "s3:PutObject"
            ],
            "Resource": [
                "arn:aws:s3:::aws-athena-query-results-*",
                "arn:aws:s3:::query-results-custom-bucket",
                "arn:aws:s3:::query-results-custom-bucket/*"
            ]
        }
    ]
}