-1

Environment = AWS-Cloud9 and using s3 buckets.

I am trying to do an Upload_file command to upload a simple .txt file from my local Desktop to one of my s3 buckets and the outcome is:

"FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/Dylan/OneDrive/Desktop/Hey.txt'"

I have double checked the paths and the file is there.

def upload_object():
    s3 = boto3.resource('s3')
s3.Bucket('dylanreed123132').upload_file('C:/Users/Dylan/OneDrive/Desktop/Hey.txt', 'Hey.txt')

I do have "Import boto3" at the begging.

*** Error Output ***
*** Welcome to the AWS S3 Functionality Console***
-Select one of the options below-
1. Create a new bucket
2. Put object in existing bucket
3. Delete object from existing bucket
4. Delete bucket
5. Copy an object from one bucket to another
6. Download an existing object from a bucket
7. Exit Program
Enter option: 2
Traceback (most recent call last):
File "/home/ec2-user/environment/HW1-S3/HW1.py", line 78, in <module>
main()
File "/home/ec2-user/environment/HW1-S3/HW1.py", line 60, in main
upload_object()
File "/home/ec2-user/environment/HW1-S3/HW1.py", line 21, in upload_object
s3.Bucket('dylanreed123132').upload_file('C:/Users/Dylan/OneDrive/Desktop/Hey.txt', 'Hey.txt')
File "/usr/local/lib/python3.7/site-packages/boto3/s3/inject.py", line 239, in bucket_upload_file
Config=Config,
File "/usr/local/lib/python3.7/site-packages/boto3/s3/inject.py", line 148, in upload_file
callback=Callback,
File "/usr/local/lib/python3.7/site-packages/boto3/s3/transfer.py", line 292, in upload_file
File "/usr/local/lib/python3.7/site-packages/s3transfer/futures.py", line 103, in result
return self._coordinator.result()
File "/usr/local/lib/python3.7/site-packages/s3transfer/futures.py", line 266, in result
raise self._exception
File "/usr/local/lib/python3.7/site-packages/s3transfer/tasks.py", line 269, in _main
self._submit(transfer_future=transfer_future, **kwargs)
File "/usr/local/lib/python3.7/site-packages/s3transfer/upload.py", line 585, in _submit
upload_input_manager.provide_transfer_size(transfer_future)
File "/usr/local/lib/python3.7/site-packages/s3transfer/upload.py", line 244, in provide_transfer_size
self._osutil.get_file_size(transfer_future.meta.call_args.fileobj)
File "/usr/local/lib/python3.7/site-packages/s3transfer/utils.py", line 247, in get_file_size
return os.path.getsize(filename)
File "/usr/lib64/python3.7/genericpath.py", line 50, in getsize
return os.stat(filename).st_size
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/Dylan/OneDrive/Desktop/Hey.txt'

Here is screenshot of the whole thing code and also the file located in the on desktop.

enter image description here

enter image description here

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Dreed66
  • 25
  • 1
  • 5
  • 1
    The error seems pretty clear to me: despite what you have written, the file is most definitely NOT there. Please edit your question to include evidence that the file is there. Also, please include the error output and your code as text rather than as images: for reasons why, see [Please do not upload images of code/data/errors.](//meta.stackoverflow.com/q/285551). – Luke Woodward Jun 27 '23 at 19:30
  • @LukeWoodward I made the suggested changes and also uploaded proof that the file is indeed located there. Any other thoughts on what it's returning this error? – Dreed66 Jun 27 '23 at 19:48
  • @Dreed66 What you see in the explorer might not what actually is on the actual filesystem. Some apps - specifically OneDrive can cause these .. Some apps default to use the "non-onedriver" path for Desktop (and docs and such). So - nothing can be concluded so far from that previous screenshot ... – rasjani Jun 27 '23 at 19:54
  • Your post includes a stack trace indicating a `/home/ec2-user/` directory. That suggests an EC2 Linux instance, not your local Windows machine. Where are you running this code? – jarmod Jun 27 '23 at 19:55
  • @jarmod I am running this code in an AWS-Cloud9 environment. What I am trying to do is up load the Hey.txt file from my local Desktop to the AWS S3 bucket 'dylanreed123132'. I have also tried from different placing the file in different locations other than Desktop and I still receive the same error message. – Dreed66 Jun 27 '23 at 20:00
  • 1
    Code running in Cloud9 cannot see anything on your desktop. If you want to access some data file on your desktop, run the code on your desktop. – Anon Coward Jun 27 '23 at 20:34

1 Answers1

0

It appears you are trying to run this AWS Code example:

https://github.com/awsdocs/aws-doc-sdk-examples/blob/main/python/example_code/s3/s3_basics/scenario_getting_started.py

This code works and has been tested many times. Looks like your issue is you are trying to run this code in an IDE in the cloud. Instead - run your Python code in an IDE such as PyCharm on your local desktop which can see your local files. Running an IDE in the cloud does not have access to files on your desktop.

smac2020
  • 9,637
  • 4
  • 24
  • 38