How to Deploy a Website in AWS S3

Rajiv thejuRajiv theju
3 min read

Introduction

Deploying a website to AWS S3 is a straightforward and cost-effective way to host static websites. In this guide, we'll walk you through the process step-by-step, ensuring your website is up and running in no time.

Step 1: Create an AWS Account

If you don’t already have an AWS account, you’ll need to create one. Visit the AWS website and follow the signup instructions.

Step 2: Set Up an S3 Bucket

  1. Log in to AWS Management Console: Go to the AWS Management Console and log in.

  2. Navigate to S3: Search for S3 in the services menu and click to open the S3 dashboard.

  3. Create a Bucket:

    • Click on "Create bucket".

    • Enter a unique bucket name (e.g., my-website-bucket).

    • Choose the AWS Region closest to your target audience.

    • Keep the default settings for the rest of the options and click "Create bucket".

Step 3: Configure the Bucket for Website Hosting

  1. Open Bucket Settings:

    • Click on the bucket name you just created.

    • Go to the "Properties" tab.

  2. Enable Static Website Hosting:

    • Scroll down to the "Static website hosting" section.

    • Select "Use this bucket to host a website".

    • Specify the index document (e.g., index.html). You can also specify an error document (e.g., error.html).

    • Click "Save changes".

Step 4: Upload Your Website Files

  1. Upload Files:

    • In the bucket overview, click on the "Upload" button.

    • Click "Add files" and select all your website files (HTML, CSS, JavaScript, images, etc.).

    • Click "Upload".

Step 5: Set Permissions

  1. Make the Bucket Public:

    • Go to the "Permissions" tab of your bucket.

    • Click on "Bucket Policy".

    • Use the following policy to make your bucket public:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Sid": "PublicReadGetObject",
          "Effect": "Allow",
          "Principal": "*",
          "Action": "s3:GetObject",
          "Resource": "arn:aws:s3:::your-bucket-name/*"
        }
      ]
    }
  • Replace your-bucket-name with the name of your bucket.

  • Click "Save changes".

Step 6: Access Your Website

  1. Find the Endpoint URL:

    • Go back to the "Properties" tab of your bucket.

    • Under "Static website hosting", you will see the "Endpoint" URL. This is the URL of your website.

  2. Visit Your Website:

    • Open the endpoint URL in your browser to see your live website.

Step 7: Optional - Configure a Custom Domain

  1. Register a Domain: If you don’t already have a domain, you can register one via AWS Route 53 or any other domain registrar.

  2. Create a Hosted Zone in Route 53:

    • Go to Route 53 in the AWS Management Console.

    • Click on "Create hosted zone" and enter your domain name.

  3. Add an S3 Bucket Policy for Redirection:

    • Create another S3 bucket with the same name as your domain (e.g., www.yourdomain.com).

    • Enable static website hosting and select the "Redirect requests" option. Enter your primary bucket's URL.

  4. Update DNS Settings:

    • In Route 53, create an Alias record that points to your primary S3 bucket's website endpoint.

Conclusion

Deploying a website to AWS S3 is a simple yet powerful way to host static websites. By following these steps, you can have your site up and running quickly, taking advantage of AWS’s scalability and reliability. If you have any questions or run into issues, the AWS documentation and community forums are great resources for additional support.

Happy hosting!

0
Subscribe to my newsletter

Read articles from Rajiv theju directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rajiv theju
Rajiv theju