<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: 59 Raviraj Tekale</title>
    <description>The latest articles on DEV Community by 59 Raviraj Tekale (@raviraj414).</description>
    <link>https://dev.to/raviraj414</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2735233%2F233fded8-7860-42f7-b044-908d60843f1e.png</url>
      <title>DEV Community: 59 Raviraj Tekale</title>
      <link>https://dev.to/raviraj414</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raviraj414"/>
    <language>en</language>
    <item>
      <title>How to Upload Files to AWS S3 with Python: A Beginner-Friendly Guide</title>
      <dc:creator>59 Raviraj Tekale</dc:creator>
      <pubDate>Sun, 19 Jan 2025 17:03:04 +0000</pubDate>
      <link>https://dev.to/raviraj414/how-to-upload-files-to-aws-s3-with-python-a-beginner-friendly-guide-98o</link>
      <guid>https://dev.to/raviraj414/how-to-upload-files-to-aws-s3-with-python-a-beginner-friendly-guide-98o</guid>
      <description>&lt;p&gt;Introduction:&lt;br&gt;
AWS S3 (Simple Storage Service) is a powerful cloud storage solution that’s widely used for storing and retrieving data of all types. Whether you’re building a backup system or a web app, learning how to upload files to S3 is a great starting point.&lt;/p&gt;

&lt;p&gt;In this post, I’ll guide you through a simple Python script that makes uploading files to S3 quick and easy. Let’s dive in!&lt;/p&gt;

&lt;p&gt;Getting Started&lt;br&gt;
To upload files to S3, we’ll use the boto3 library, Amazon’s SDK for Python. This library allows you to interact with AWS services, including S3, in just a few lines of code.&lt;/p&gt;

&lt;p&gt;Step 1: Install the Required Library&lt;br&gt;
First, make sure you have Python installed on your system. Then, install boto3 using pip:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
Copy&lt;br&gt;
Edit&lt;br&gt;
pip install boto3&lt;br&gt;
This library will handle the interaction with S3 for us.&lt;/p&gt;

&lt;p&gt;Step 2: Set Up Your AWS Credentials&lt;br&gt;
You need AWS credentials to connect to your account. Follow these steps:&lt;/p&gt;

&lt;p&gt;Log in to the AWS Management Console.&lt;br&gt;
Navigate to the IAM (Identity and Access Management) service.&lt;br&gt;
Create a new user with programmatic access and attach the policy AmazonS3FullAccess.&lt;br&gt;
Download the access key and secret key.&lt;br&gt;
Configure these credentials locally using the AWS CLI:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
Copy&lt;br&gt;
Edit&lt;br&gt;
aws configure&lt;br&gt;
Enter the access key, secret key, and default region when prompted.&lt;/p&gt;

&lt;p&gt;Step 3: Write the Python Script&lt;br&gt;
Here’s a simple script to upload files to an S3 bucket:&lt;/p&gt;

&lt;p&gt;python&lt;br&gt;
Copy&lt;br&gt;
Edit&lt;br&gt;
import boto3&lt;br&gt;
from botocore.exceptions import NoCredentialsError&lt;/p&gt;

&lt;p&gt;def upload_to_s3(file_name, bucket, object_name=None):&lt;br&gt;
    """&lt;br&gt;
    Upload a file to an S3 bucket.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:param file_name: Name of the file to upload
:param bucket: S3 bucket name
:param object_name: S3 object name (optional)
:return: None
"""
s3 = boto3.client('s3')
try:
    s3.upload_file(file_name, bucket, object_name or file_name)
    print(f"File '{file_name}' successfully uploaded to bucket '{bucket}'")
except FileNotFoundError:
    print(f"Error: The file '{file_name}' was not found.")
except NoCredentialsError:
    print("Error: AWS credentials not available.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Step 4: Run the Script&lt;br&gt;
Replace the placeholder values (file_name, bucket, etc.) in the script.&lt;br&gt;
Example:&lt;br&gt;
python&lt;br&gt;
Copy&lt;br&gt;
Edit&lt;br&gt;
upload_to_s3('example.txt', 'my-s3-bucket')&lt;br&gt;
Save the script as upload_to_s3.py.&lt;br&gt;
Run it in your terminal:&lt;br&gt;
bash&lt;br&gt;
Copy&lt;br&gt;
Edit&lt;br&gt;
python upload_to_s3.py&lt;br&gt;
If everything is set up correctly, the file will be uploaded to your S3 bucket.&lt;/p&gt;

&lt;p&gt;Lessons Learned&lt;br&gt;
Error Handling is Key: Always account for common issues, such as missing credentials or incorrect file paths.&lt;br&gt;
S3 is Versatile: Beyond simple file uploads, you can use S3 for hosting static websites, backups, and more.&lt;br&gt;
AWS is Developer-Friendly: With libraries like boto3, even complex cloud interactions become simple.&lt;br&gt;
Conclusion&lt;br&gt;
Uploading files to AWS S3 is a great first step in exploring cloud computing. By using Python and boto3, you can easily integrate S3 into your projects.&lt;/p&gt;

&lt;p&gt;If you found this guide helpful, feel free to check out more of my AWS content [here]. Happy coding!&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
