Intermittent 'PermissionError: Access Denied' when trying to read S3 file from AWS Lambda
See original GitHub issueI’m running a Python 3.7 script in AWS Lambda, which runs queries against AWS Athena and tries to download the CSV results file that Athena stores on S3 once the query execution has completed.
Any ideas why I’d be running into the error below intermittently?
s3_query_result_path = f's3://{bucket}/{results_key}'
[ERROR] PermissionError: Access Denied
Traceback (most recent call last):
File "/var/task/lambdas/process_file/lambda_function.py", line 91, in lambda_handler
df = pd.read_csv(s3_query_result_path)
File "/var/task/pandas/io/parsers.py", line 685, in parser_f
return _read(filepath_or_buffer, kwds)
File "/var/task/pandas/io/parsers.py", line 440, in _read
filepath_or_buffer, encoding, compression
File "/var/task/pandas/io/common.py", line 207, in get_filepath_or_buffer
filepath_or_buffer, encoding=encoding, compression=compression, mode=mode
File "/var/task/pandas/io/s3.py", line 36, in get_filepath_or_buffer
filepath_or_buffer = fs.open(_strip_schema(filepath_or_buffer), mode)
File "/var/task/fsspec/spec.py", line 669, in open
autocommit=ac, **kwargs)
File "/var/task/s3fs/core.py", line 303, in _open
autocommit=autocommit)
File "/var/task/s3fs/core.py", line 920, in __init__
cache_type=cache_type)
File "/var/task/fsspec/spec.py", line 864, in __init__
self.details = fs.info(path)
File "/var/task/s3fs/core.py", line 479, in info
return super().info(path)
File "/var/task/fsspec/spec.py", line 477, in info
out = self.ls(self._parent(path), detail=True, **kwargs)
File "/var/task/s3fs/core.py", line 497, in ls
files = self._ls(path, refresh=refresh)
File "/var/task/s3fs/core.py", line 430, in _ls
return self._lsdir(path, refresh)
File "/var/task/s3fs/core.py", line 336, in _lsdir
raise translate_boto_error(e)
As you can see above, I’m using the pandas library, which then uses s3fs under the hood.
The Lambda works about 80% of the time, and I can’t figure out anything unique about the times it fails.
Feel free to let me know if I should be posting this question in pandas or elsewhere instead - thanks for your help!
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:63 (19 by maintainers)
Top Results From Across the Web
Access Denied' when trying to read S3 file from AWS Lambda ...
I'm running a Python 3.7 script in AWS Lambda, which runs queries ... Intermittent 'PermissionError: Access Denied' when trying to read S3 ......
Read more >aws lambda function getting access denied when getObject ...
I was trying to read a file from s3 and create a new file by changing content of file read (Lambda + Node)....
Read more >Fix cross-account Access Denied errors when using Lambda ...
Short description. If the permissions between a Lambda function and an Amazon S3 bucket are incomplete or incorrect, then Lambda returns an Access...
Read more >Resolve "Access Denied" errors when running Athena queries
When I run an Amazon Athena query, I get an "Access Denied" error. ... The object owner is different from the Amazon S3...
Read more >Debugging AccessDenied in AWS IAM - NoDrama DevOps
I used this approach to dive into and climb out of a deep access control rabbit hole of cross-account access involving: IAM, Lambda,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We came across a similar problem beginning with s3fs==0.3.0. It was a FileNotFoundError message, however, but also unpredictably intermittent (approximately 15-20% of the time) and within a lambda that was being triggered by the presence of a file in an S3 bucket. The issue occurred with files as small as 18kb. Unfortunately, I can’t reproduce it outside of our production environment, where we’ve stuck with s3fs==0.2.2. This is the stack trace from last time we had the issue, which was using s3fs==0.3.1:
Also, just to restate the obvious, this problem doesn’t occur with s3fs 0.2.0 (which is what I’m using now) so whatever you were doing before was working just fine.