Today we will talk about how to download , upload file to Amazon S3 with Boto3 Python.
Before we start , Make sure you notice down your S3 access key and S3 secret Key.
Before we could work with AWS S3. We need to configure it first.
- Install awscli using pip
pip install awscli
AWS Access Key ID [None]: input your access key
AWS Secret Access Key [None]: input your secret access key
Default region name [None]: input your region
Default output format [None]: json
aws s3 ls
if you see there is your bucket show up. it mean your configure is correct. Ok, Now let's start with upload file.
bucketName = "Your S3 BucketName"
Key = "Original Name and type of the file you want to upload into s3"
outPutname = "Output file name(The name you want to give to the file after we upload to s3)"
s3 = boto3.client('s3')
Bucket = "Your S3 BucketName"
Key = "Name of the file in S3 that you want to download"
outPutName = "Output file name(The name you want to save after we download from s3)"
s3 = boto3.resource('s3')
except botocore.exceptions.ClientError as e:
if e.response['Error']['Code'] == "404":
print("The object does not exist.")