Unable to access AWS S3 - Error : java.nio.file.AccessDeniedException

rs5
Visitor

I am performing encryption over 40M records using serverless compute. The code is working fine on 50 records but failing on 40M while displaying and selecting as well but sometimes it is working and showing results. 

Error:

Job aborted due to stage failure: com.databricks.sql.io.FileReadException: Error while reading file s3://mercury-dev-data-forge-bucket/__unitystorage/catalogs/770bafe/tables/e514sadasdsadsaf/part-00013-cf2821e8-a549-4f08-adhgdf-b0a540.c000.zstd.parquet.

Sometimes I am able to run it without any errors, and other times I get this error. Why is that?

szymon_dybczak
Esteemed Contributor III

Hi @rs5 ,

Could you provide full stack trace of the exception?

Avi3
Databricks Employee
Databricks Employee

On S3, one possibility is that some of the data files are missing, which can happen for various reasons.

As a first step, could you check whether the file mentioned in the error actually exists in S3?

s3://mercury-dev-data-forge-bucket/__unitystorage/catalogs/770bafe/tables/e514sadasdsadsaf/part-00013-cf2821e8-a549-4f08-adhgdf-b0a540.c000.zstd.parquet

If the file exists, another test I would recommend is running the same query on a dedicated cluster instead of serverless.

Please let us know the results. These steps should help us narrow down the root cause.

I have checked the files are available on s3 and same issue on another cluster. Also checked the permissions which are fine.

Avi3
Databricks Employee
Databricks Employee

Thanks, have you tried using a dedicated cluster or another serverless?

Also, it could be that the files have been archived and while visible to you not visible from Databricks.
You can try running these on the exact file from the error, ideally with the same IAM role your Unity Catalog storage credential uses?

aws s3api head-object --bucket mercury-dev-data-forge-bucket --key <path-to-failing-part-file>
aws s3 cp s3://mercury-dev-data-forge-bucket/<path-to-failing-part-file> /tmp/test.parquet

Please share:
1. The head-object output, in particular StorageClass, ArchiveStatus (if present) and SSEKMSKeyId.
2. Whether aws s3 cp succeeds, or the exact error it returns.
3. The full stack trace, especially the innermost Caused by with the S3 error code (AccessDenied / ExpiredToken / InvalidObjectState / KMS).
4. Whether the failing file is always the same one, or a different file each time.

HongC
New Contributor

I had something similar on serverless, turned out not to be a "real" permissions problem on the whole table, just some files.

the 50 record test probably reads 1-2 files, 40M reads all of them, so you only hit the bad one on the big run. thats why it looks random. couple things id check:

  • KMS: if the bucket uses SSE-KMS, check part-00013 with aws s3api head-object, its possible some files were written with a different key and the UC storage credential role cant decrypt them. that was our issue
  • S3 returns 403 instead of 404 when the file is gone and the role has no ListBucket. if you are overwriting the same table you read from (encrypt and write back) or something else is writing to it at the same time, the old files disappear mid read. check DESCRIBE HISTORY around the failure time
  • bucket policy with SourceVpc / SourceIp conditions, these block serverless since it doesnt run in your VPC. try the same thing on a classic cluster, if it never fails there its probably this

easiest way to know for sure is CloudTrail, filter on that object key and the time of the error, it tells you exactly who got denied and why