DEV Community

Cover image for Creating an Amazon S3 Bucket for storing media and static files for your website
MikaZuki Augus
MikaZuki Augus

Posted on

Creating an Amazon S3 Bucket for storing media and static files for your website

Introduction:

Image description

Amazon S3 (Simple Storage Service) is an object storage service that offers scalability, data availability, security, and performance. In this tutorial, we will guide you through the process of creating an Amazon S3 bucket to store your website's media and static files. By the end of this guide, you'll have a fully configured S3 bucket ready to store and retrieve any amount of data at any time, from anywhere on the web.

Prerequisites:

Before you begin, make sure you have:

An active AWS account. If you don't have one, you can sign up for free at https://aws.amazon.com/.
Access to AWS Management Console.

Step 1: Open the Amazon S3 Console

1.1. Sign in to your AWS Management Console and navigate to the S3 service. You can find this under "Storage" in the "Services" menu.

Step 2: Create a Bucket

2.1. Click on the "Create Bucket" button.
2.2. Enter a unique DNS-compliant name for your new bucket.
2.3. Choose the AWS Region where you want the bucket to reside.
2.4. Leave the remaining options at their defaults for now, and click on the "Create Bucket" button.

Step 3: Configure the Bucket for Static Website Hosting

3.1. Once your bucket is created, click on the bucket name from the dashboard to open it.
3.2. Navigate to the "Properties" tab and scroll down to the "Static website hosting" section.
3.3. Select the "Use this bucket to host a website" option.
3.4. Specify the names of your index and error documents. The index document is the default or home page for your website.

Step 4: Set the Bucket Policy

4.1. Go to the "Permissions" tab and click on "Bucket Policy."
4.2. Enter a policy that allows public read access to your bucket. For example:

{
   "Version":"2012-10-17",
   "Statement":[{
    "Sid":"PublicReadGetObject",
        "Effect":"Allow",
      "Principal": "*",
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3:::your_bucket_name/*"
      ]
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Replace "your_bucket_name" with the actual name of your S3 bucket.

Step 5: Upload Your Website Files

5.1. Navigate to the "Objects" tab and click the "Upload" button.
5.2. Use the file dialog to select your website's static and media files, then click the "Upload" button.

Conclusion:

Congratulations! You've successfully created an Amazon S3 bucket and configured it to host your website's static and media files. Now, you have a scalable, secure, and highly available solution to store your website data. With the scalability of Amazon S3, your website can handle any amount of traffic and data will always be served at high speed.

Remember, Amazon S3 also provides robust features such as version control, event notifications, and logging to further enhance the management of your data. Happy hosting on AWS S3!

Image description

Follow me on Twitter: @CodezMikazuki

Thanks for reading, Malcz/Mika

Top comments (0)