skip to Main Content

I need to download a file from aws bucket ( name known ) and object name know. But access key id and secret key are not known.

import boto3
import pandas as pd

s3 = boto3.client('s3')

s3 = boto3.resource(service_name='s3')
s3.Bucket('yz').download_file(Key='keh.docx', Filename='keh.docx')

Getting the Following error
NoCredentialsError: Unable to locate credentials

Is there any way that we can download a file without secret key and access id?

2

Answers


  1. Is there any way that we can download a file without secret key and access id?

    Yes, if the object is public. Then you don’t need any credentials. Also you can download objects with credentials if you have S3 pre-signed url for the object.

    In all other cases, credentials are required in one form or the other.

    Login or Signup to reply.
  2. An example from the boto3 documentation

    Import boto3
    
    s3 = boto3.client('s3')
    s3.download_file('BUCKET_NAME', 'OBJECT_NAME', 'FILE_NAME')
    

    If the file is in a public bucket, you can only use the request package.

    import queries
    url = 'http://s3.amazonaws.com/[bucket_name]/[path_to_file]/file'
    file = requests.get(url, allow_redirects=True)
    open('./file', 'wb').write(file.content)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search