Boto3 is installed but when I try to use the below function to upload an image to an S3 bucket I get global name 's3' is not defined error.
Is there something I'm missing?
import logging
import boto3
from botocore.exceptions import ClientError
import os
def upload_file(file_name, bucket, object_name=None):
if object_name is None:
object_name = os.path.basename(file_name)
s3_client = boto3.resource('s3')
try:
response = s3.client.upload_file(file_name, bucket,
object_name)
except ClientError as e:
logging.error(e)
return False
return True
upload = upload_file('test1.jpg','mybucket', 'test1.jpg')
CodePudding user response:
This line:
response = s3.client.upload_file(file_name, bucket, object_name)
should be:
response = s3_client.upload_file(file_name, bucket, object_name)