How to upload file in S3 bucket in python

In this tutorial will learn about file uploading in s3 bucket and how to perform data storage with AWS s3 bucket using python.

s3_upload_file

What is Amazon Web Services (AWS) S3 bucket

It is providers object storage which is actually built for storing and recover any amount of data from anywhere over the internet.

Why S3 bucket is popular

  • basically it is known for storing data and data is more secure and fast uploading and fast retrieving data from s3 bucket. Durability is 99.999999999%.
  • if you need any time data then availabilty is 99.99%.
  • cost effective
  • scalabilty
  • security

  • Example of uploading data in S3 Bucket


    Get Your Access Key ID, Access Secret Key and Bucket Name

    Access Key ID, Access Secret Key and Buckent Name will be required for programming if you don't have these details then just you need to generate Access Key, Access Secret and Buckent name from AWS Management Console.

    Install boto3

    If you are using python version 2.x .then use the below code

    pip install boto3

    If you are using python version 3.x . then use the below code

    pip3 install boto3

    Python code for uploading


    import boto3 from botocore.client import Config ACCESS_KEY_ID = 'XXXXXXXXXXXXXXXXXXXXXX' ACCESS_SECRET_KEY = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX' BUCKET_NAME = 'XXXXXXXX' def s3bucket_upload_files(FILE_NAME,IMAGE_PATH): data = FILE_NAME s3 = boto3.resource('s3',aws_access_key_id=ACCESS_KEY_ID,aws_secret_access_key=ACCESS_SECRET_KEY,config=Config(signature_version='s3v4') ) s3.Bucket(BUCKET_NAME).put_object(Key=IMAGE_PATH, Body=data) return "success" s3bucket_upload_files(FILE_NAME,IMAGE_PATH)

    Hope you like it , please comment if you have any doubt .

    Free live cricket score API for python

    Post a Comment

    0 Comments