Unable to fetch file from s3 with api

Abhishek kumar

I am trying to fetch a file from an s3 bucket. I have written the code using Chalice microservice of aws.

I am unable to understand how to solve this. As I am very new to aws and as per my understanding I gave permission to the IAM role of s3 full acess . What should I do?

This is the error I am getting.

Traceback (most recent call last):
  File "/var/task/chalice/app.py", line 1112, in _get_view_function_response
    response = view_function(**function_args)
  File "/var/task/app.py", line 58, in fetch
    s3.Bucket(os.environ["BUCKET_NAME"]).download_file( 'key', 'key.pem')
  File "/var/task/boto3/s3/inject.py", line 246, in bucket_download_file
    ExtraArgs=ExtraArgs, Callback=Callback, Config=Config)
  File "/var/task/boto3/s3/inject.py", line 172, in download_file
    extra_args=ExtraArgs, callback=Callback)
  File "/var/task/boto3/s3/transfer.py", line 307, in download_file
    future.result()
  File "/var/task/s3transfer/futures.py", line 106, in result
    return self._coordinator.result()
  File "/var/task/s3transfer/futures.py", line 265, in result
    raise self._exception
  File "/var/task/s3transfer/tasks.py", line 126, in __call__
    return self._execute_main(kwargs)
  File "/var/task/s3transfer/tasks.py", line 150, in _execute_main
    return_value = self._main(**kwargs)
  File "/var/task/s3transfer/download.py", line 571, in _main
    fileobj.seek(offset)
  File "/var/task/s3transfer/utils.py", line 367, in seek
    self._open_if_needed()
  File "/var/task/s3transfer/utils.py", line 350, in _open_if_needed
    self._fileobj = self._open_function(self._filename, self._mode)
  File "/var/task/s3transfer/utils.py", line 261, in open
    return open(filename, mode)
OSError: [Errno 30] Read-only file system: 'key.pem.a7A6afCF'

Code associated:

    s3 = boto3.resource('s3')
    # s3.Bucket(os.environ["BUCKET_NAME"]).upload_file(Filename="requirements.txt" , Key="tryagain")
    s3.Bucket(os.environ["BUCKET_NAME"]).download_file( 'key', 'key.pem')

Thanks for your help.

Marcin

Since the code is being executed on lambda due do the use of Chalice, files downloaded from S3 should be stored in /tmp, rather then in the location where the lambda function code is being executed.

The proposed solution is to change:

s3.Bucket(os.environ["BUCKET_NAME"]).download_file( 'key', 'key.pem')

into:

s3.Bucket(os.environ["BUCKET_NAME"]).download_file('key', '/tmp/key.pem')

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Chrome unable to fetch css from s3 in service worker

From Dev

Unable to fetch my data from JSON file due to fetch api error

From Dev

Unable fetch the api's data

From Dev

Fetch data from .json file with fetch api

From Dev

AWS Lambda unable to GET a file from S3

From Dev

Unable to download a file from S3 by the URL in a browser

From Dev

Unable to fetch json file from android assets

From Dev

unable to fetch data from json file in angularjs?

From Dev

Unable to fetch data from properties file

From Java

Unable to fetch JSON as String from a REST API

From Dev

Unable to fetch data from api in react

From Dev

Unable to fetch any response from the api (Volley)

From Dev

Unable to fetch data from MySQL database with Fetch API

From Dev

Download file from Amazon S3 using REST API

From Dev

File download from API to Meteor server and upload to S3

From Dev

Download file from AWS S3 using fetch method throws CORS error

From Dev

How to fetch all columns from table and save it in s3 as csv file using python

From Dev

How to fetch all columns from table and save it in s3 as csv file using python

From Dev

fetch api (GET DATA) from php file

From Dev

ReactJS fetch data from api json file

From Dev

Unable to restore SQL Server bak file from S3, says file too large

From Dev

Unable to download file from s3 using return response()->download($file);

From Dev

Laravel getID3 unable to pull file from S3

From Dev

Unable to fetch data from 3rd party api in NestJs showing Error 412

From Dev

Unable to Reference a S3 file in Terraform

From Dev

Unable to upload file from Elastic Beanstalk to s3 due to access denied

From Dev

How to read an .xls file from AWS S3 using spark in java? And unable to read sheetName

From Dev

Unable to Parse JSON file from S3 in AWS Quick Sight

From Dev

Unable to access S3 file with IAM role from EC2

Related Related

  1. 1

    Chrome unable to fetch css from s3 in service worker

  2. 2

    Unable to fetch my data from JSON file due to fetch api error

  3. 3

    Unable fetch the api's data

  4. 4

    Fetch data from .json file with fetch api

  5. 5

    AWS Lambda unable to GET a file from S3

  6. 6

    Unable to download a file from S3 by the URL in a browser

  7. 7

    Unable to fetch json file from android assets

  8. 8

    unable to fetch data from json file in angularjs?

  9. 9

    Unable to fetch data from properties file

  10. 10

    Unable to fetch JSON as String from a REST API

  11. 11

    Unable to fetch data from api in react

  12. 12

    Unable to fetch any response from the api (Volley)

  13. 13

    Unable to fetch data from MySQL database with Fetch API

  14. 14

    Download file from Amazon S3 using REST API

  15. 15

    File download from API to Meteor server and upload to S3

  16. 16

    Download file from AWS S3 using fetch method throws CORS error

  17. 17

    How to fetch all columns from table and save it in s3 as csv file using python

  18. 18

    How to fetch all columns from table and save it in s3 as csv file using python

  19. 19

    fetch api (GET DATA) from php file

  20. 20

    ReactJS fetch data from api json file

  21. 21

    Unable to restore SQL Server bak file from S3, says file too large

  22. 22

    Unable to download file from s3 using return response()->download($file);

  23. 23

    Laravel getID3 unable to pull file from S3

  24. 24

    Unable to fetch data from 3rd party api in NestJs showing Error 412

  25. 25

    Unable to Reference a S3 file in Terraform

  26. 26

    Unable to upload file from Elastic Beanstalk to s3 due to access denied

  27. 27

    How to read an .xls file from AWS S3 using spark in java? And unable to read sheetName

  28. 28

    Unable to Parse JSON file from S3 in AWS Quick Sight

  29. 29

    Unable to access S3 file with IAM role from EC2

HotTag

Archive