DEV Community

Sunil Yaduvanshi
Sunil Yaduvanshi

Posted on

Building Your Own Music App Using AWS S3 Bucket Static Web Hosting

In today’s digital world, music streaming services have revolutionized the way we listen to our favorite tunes. With AWS, you can build your own simple music app that allows you to host and stream music directly from an S3 bucket. This guide will walk you through the process of creating a static website hosted on AWS S3 and uploading your music files to S3 for seamless playback.

Step 1: Set Up Your AWS S3 Bucket

Image description

  1. Create an S3 Bucket:

    • Sign in to the AWS Management Console and navigate to the S3 service.
    • Click on "Create bucket."
    • Enter a unique bucket name (e.g., musicbucket).
    • Choose the AWS Region closest to your target audience.
    • Leave the remaining settings as default and click "Create bucket."
  2. Enable Static Website Hosting:

    • Click on your newly created bucket to open its settings.
    • Go to the "Properties" tab.
    • Scroll down to "Static website hosting" and click "Edit."
    • Choose "Enable" and then select "Host a static website."
    • Enter your "Index document" (e.g., index.html).
    • Click "Save changes."

Image description

  1. Configure Bucket Permissions:

    • Go to the "Permissions" tab in your bucket settings.
    • Click on "Bucket policy" and insert the following JSON policy to allow public access:
     {
       "Version": "2012-10-17",
       "Statement": [
         {
           "Sid": "PublicReadGetObject",
           "Effect": "Allow",
           "Principal": "*",
           "Action": "s3:GetObject",
           "Resource": "arn:aws:s3:::muscibucket/*"
         }
       ]
     }
    
  • Replace musicbucket with your bucket name.
  • Save the bucket policy.

Image description

Step 2: Upload Your Music Files

  1. Upload Music Files to S3:
    • In your S3 bucket, click on the "Upload" button.
    • Drag and drop your music files (e.g., .mp3, .wav).
    • Click "Upload" to add these files to your S3 bucket.

Image description

  1. Set Permissions for Music Files:
    • After uploading, select your music files.
    • Click on "Actions" and choose "Make public."
    • This allows anyone with the URL to access and stream the music files.

Step 3: Create a Simple HTML Page

  1. Create an HTML File:

    • On your local machine, create a simple HTML file (index.html) that will serve as the homepage of your music app.
    • Here’s an example of a basic HTML structure for your music player:
     <!DOCTYPE html>
     <html lang="en">
     <head>
         <meta charset="UTF-8">
         <meta name="viewport" content="width=device-width, initial-scale=1.0">
         <title>My Music App</title>
     </head>
     <body>
         <h1>Serverless Music App</h1>
         <audio controls>
    <source src="https://musicbucket.s3.amazonaws.com/your-music-file.mp3" type="audio/mpeg">
             Your browser does not support the audio element.
         </audio>
     </body>
     </html>
    
  • Replace the src URL with the actual link to your music file in the S3 bucket.
  1. Upload the HTML File to S3:
    • Upload the index.html file to your S3 bucket.
    • Make sure this file is also set to public so that it can be accessed by users.

Image description

Step 4: Access Your Music App

  1. Get the Endpoint URL:
    • Go back to the "Properties" tab of your S3 bucket.
    • Under "Static website hosting," you’ll find the "Bucket website endpoint."
  2. Copy this URL; this is your music app’s address (e.g., http://my-musicbucket.s3-website-us-west-2.amazonaws.com).

  3. Open Your App in a Browser:

    • Paste the endpoint URL into your browser.
    • You should see your music app with the audio player ready to play your uploaded music.

Image description

Step 5: Enhance Your Music App (Optional)

To make your music app more functional and visually appealing, consider the following enhancements:

  • Add CSS Styles: Improve the appearance of your app by adding a style.css file.
  • Create a Playlist: Allow users to select from multiple tracks by listing them on the page.
  • Add JavaScript: Implement features like autoplay, shuffle, and volume control using JavaScript.
  • Enable HTTPS: Use Amazon CloudFront to serve your static website over HTTPS for better security.

Image description

Image description

Conclusion

With AWS S3, you can quickly set up and host a simple music streaming app that allows you to share and play your music files. This project demonstrates how AWS S3’s static web hosting can be used for more than just serving webpages—it’s a versatile tool for hosting multimedia content. Start experimenting with your own music app and see how far you can take it!

Top comments (1)

Collapse
 
zubizubi profile image
Aaron Aaron

Thanks for sharing this great information! It has inspired me to create my own app and website similar to Snaptube music app. I see the potential in offering a platform for easy video and music downloads. Looking forward to developing and launching it soon for everyone to use!