Search code examples
amazon-web-servicesamazon-s3amazon-ec2amazon-route53elastic-ip

S3 bucket with same CNAME as app?


I have the following setup:

  • Domain registered mydomain.com
  • App hosted on EC2 webserver on port 80 that's a accessible right now at mydomain.com/myapp
  • .csv files hosted on an S3 bucket named myapp at the following endpoint like so: s3-us-west-2.amazonaws.com/myapp/sample_file.csv
  • Route 53 to deal with CNAME for my domain and an Elastic IP

Everything works fine. However, now I want to update the URL's in my app to mask the longer AWS prefix and replace it instead with: mydomain.com/myapp/sample_file.csv

Every tutorial I've seen deals with subdomains like: myapp.mydomain.com/sample_file.csv which I DON'T want (since this particular app should only be accessed at the /myapp URL)

Is this possible?


Solution

  • You could point a custom domain name to your Amazon S3 bucket. The basic steps are:

    • Create an Amazon S3 bucket with a name that matches your domain name (eg dl.mydomain.com)
    • Activate Static Website Hosting on the bucket
    • Create a Record Set in Amazon Route 53 for the dl subdomain:
      • Type A
      • Alias = yes
      • Select the Static website for your bucket

    Details: Example: Setting Up a Static Website Using a Custom Domain

    Then, put objects in the bucket within the myapp directory, eg myapp/file.csv. You will then be able to access the file via: dl.mydomain.com/myapp/file.csv