Follow on
Tuesday, June 2, 2020

Step by Step Procedure to Upload a file in AWS S3 Bucket using Python

In this blog post, I am going to share the Step by Step procedure to upload a text file into Amazon Web Service S3 bucket using Python.

Steps by Step Procedure

Step 1: Login to your AWS Console

Step 2: In the Services -> Select S3

Step 3: Create a S3 Bucket with a unique name ( The bucket in which the file has to be uploaded using Python script)

Step 4: After creating the bucket, In the Services go to IAM

Step 5: Select the Users

Step 6: In the list of Users, Select a user through whom you want to upload file.

Step 7: Go to Security Credentials Tab

Step 8: Click on the Create Access key

Step 9: Copy the Access key and Secret key displayed on the screen

Step 10: Open your python development environment.

Step 11: Boto3 package will be required to install for uploading the file to S3 bucket. Use the below steps to install boto3 package. Kindly ignore, if already installed. 

 Note: If you are getting a error that, boto3 package is not available. Follow the below steps to install boto3

Step 1: Go to the command prompt

Step 2: Navigate to the folder in which pip file is available.

Step 3: Type the following command

pip install boto3

boto3 package will be added to your python library.

Step 12: After installing the boto3 package, type the below script in your python development environment

import boto3
from botocore.exceptions import NocredentialsError

AccessKey = 'place your access key here'
SecrertKey = 'place your secret key here'

def awsUpload_file(uploadfile, bucketname, s3file)
    s3 = boto3.client('s3',aws_access_key=AccessKey, aws_secretkey=SecretKey)
        return true
    except fileNotFoundError:
        print("File not found")
        return false
    except NoCredentialsError:
        print(credentials error")
        return false

f = open("full path address of the file", "w+")

awsUpload = awsUpload_file("full path address of the file",'bucket name','filename in s3')

Note: Make sure to give the full path address of the file using \\

Example: C:\\ABC\\file.txt

Step 13: Save and run the script.

Step 14: File will be uploaded in the specified S3 bucket.

Happy uploading file into S3 bucket.!
  • Blogger Comments
  • Facebook Comments


Post a Comment

Item Reviewed: Step by Step Procedure to Upload a file in AWS S3 Bucket using Python Rating: 5 Reviewed By: Praveen Kumar Rajendran