Python script from Cloud9 IDE trying to upload to AWS s3 bucket showing "No such file or directory"

47 Views Asked by At

I am working a college assignment where one of the steps is to upload an object into an S3 bucket using Cloud9 IDE. After trying in my main code, I did some research and found a youtube video tutorial that I that I copied the code below.

This code is still throwing the no file or directory error even though the file clearly is created. I have tried specifying the path directly and moving the text document around but nothing seems to work. I am not sure what else to do, seems like no matter what directory I point to, cloud9 says there's nothing there.

import os
import boto3

client = boto3.client('s3')
bucket = 'fname-lname-102823'
cur_path = os.getcwd()
file = 'hw1-object.txt'
filename = os.path.join(cur_path, 'data', file)

print(filename)

data = open(filename, 'rb')

client.upload_file(filename, bucket, file)
Nester - SD40
└── Homework1
    ├── file_upload.py
    └── hw1-object.txt
1

There are 1 best solutions below

0
Ermiya Eskandary On

Based on your file structure, this is incorrect:

filename = os.path.join(cur_path, 'data', file)

The data folder doesn't exist; try:

filename = os.path.join(cur_path, file)