Hosting dynamic website in Amazon server - amazon-s3

I am working on a project where we are hosting our files(only uploaded by the user) in S3 Amazon server. Now the problem is the contents hosted with amazon is loading fastly. But the JS, CSS and CSS images(Very small images) which hosted in our server is taking too much time to load. Is there anyway to host our entire dynamic website to Amazon S3 and is it possible to configure the DNS to amazon?

Host your static files to S3 as well.
Create a bucket named static.yourcompany.com
CName the bucket URL as static.yourcomapany.com
In your webpages, use absolute path for CSS, JS, images with base URL as http://static.yourcompany.com
You may want to leverage tools like JetS3t for syncing the files with the latest changes.
Refer:
How to alias your subdomain with S3
JetS3t Docs
Virtual Hosting of Buckets
Host Your Static Website on S3

You can also read this blog, the author has described the process in a very detailed manner
http://geekospace.com/hosting-static-web-sites-in-aws-simple-storage-service/

For the dynamic part of your website look into http://aws.amazon.com/elasticbeanstalk/ but route 53 is essentially a way to configure DNS to amazon. http://docs.aws.amazon.com/AmazonS3/latest/dev/website-hosting-custom-domain-walkthrough.html

Related

How can I host my website on an EC2 Server using Apache but host my images on S3 under the same sub domain?

So I have my website hosted on an EC2 server running apache. All works fine and well.
The issue I'm having is that I want my images hosted on S3 (and possibly cached on CloudFront), not on my EC2 server, but want both accessible under the same domain/subdomain.
For example say my website is www.helloworld.com. I want my images to be accessible at www.helloworld.com/images/foobar.png. I want foobar.png to be hosted on S3 and not each one of my EC2 servers though. How can I go about doing this?
Is there and configuration I can do in the AWS console or are there any rewrite rules I can use in Apache? I know I could always just set up a controller that will download the images from S3 and forward them to the user, but this seems wrong to me.
For that you need to put a load-balancer/proxy in front to intercept all requests and dispatch accordingly. That may not be a bad idea anyway (for availability reasons), but a separate host name for images should not be a problem, either (it's not like users will have to see or type those URL).
Using CloudFront, you can have CloudFront receive the initial requests, then based on the path, forward the request to either your EC2 instance or to your S3 bucket.
For example, you could setup the following:
A CloudFront behaviour that upon a path under /images/ would use an S3 origin, and
A default (for everything else) would go to your EC2 instance origin.

How to point Amazon S3 bucket to test subdomain like images.develop.example.com

Currently I'm using Amazon S3 bucket for my website like images.example.com .Today I also built a test subdomain for development purposes and it is served in develop.example.com
Now I want to use Amazon S3 bucket like develop.images.example.com or images.develop.example.com (I don't know which of them is correct)
Is it possible according to S3 restrictions?
Because Amazon says: You must have same bucket name with your subdomain. So I was create a bucket like images.example.com
and my cname record is: images.example.com.s3-website.eu-west-2.amazonaws.com
My webserver is Apache and runs on Ubuntu
How can reach to my images on my development subdomain?
Should I create a new cname record?
Should I do something on my virtual host file?
or what?
To share static content from develop.images.example.com:
Create an Amazon S3 bucket called develop.images.example.com
Turn on static website hosting
Create a Route 53 A record for develop.images.example.com with Alias=YES and point it to your S3 bucket
This is the same process as you would have followed for images.example.com.

Issues with PHP file from static website hosted off Amazon S3

Since Amazon offers a great way to run static sites off S3. I am using it for one of the static HTML site which doesn't have any dynamic content. The issue is am using a link.php for one of the outgoing links on the page and when i click the link, instead of reading PHP and redirecting me to external site, it forces me to download the file. Is this becoz S3 can't understand PHP?
Is there any way out? Appreciate if anyone can help.
S3 is just one big storage bucket. It doesn't support dynamic content. You would need an EC2 instance to run something that understands PHP.

Using amazon s3, upload files using their servers but URL should appear to be from mine

Is it possible to upload files to amazon S3, using their servers (i.e. my server shouldn't be used in the upload process)?
I also want the URL to appear to be uploading to my server, is this possible?
Look here for instructions on how to setup your CNAME record so that one of your subdomains can be an alias for an Amazon S3 bucket.
Depending on your needs, you might not want "s3.amazonaws.com" to appear on your web site or service. For example, if you host your web site's images on Amazon S3, you might prefer http://images.johnsmith.net/ to http://johnsmith-images.s3.amazonaws.com/

Is there a way to have index.html functionality with content hosted on S3?

Is there a way to make S3 default to an index.html page? E.g.: My bucket object listing:
/index.html
/favicon.ico
/images/logo.gif
A call to www.example.com/index.html works great! But if one were to call www.example.com/ we'd either get a 403 or a REST object listing XML document depending on how bucket-level ACL was configured.
So, the question: Is there a way to have index.html functionality with content hosted on S3?
For people still struggling against this after 3 years, let me add some important information:
The URL for your website (and to which you have to point your DNS) is not
<bucket_name>.s3-us-west-2.amazonaws.com, but
<bucket_name>.s3-website-us-west-2.amazonaws.com.
If you use the first, it will not work as intended, no matter how much you config the Index document.
For a specific example, consider:
http://www-example-com.s3.amazonaws.com/index.html works.
http://www-example-com.s3.amazonaws.com/ fails with AccessDenied.
http://www-example-com.s3-website-us-west-2.amazonaws.com/ works!
To get your true website address, go to your S3 Management Console, select the target bucket, then Properties, then Static Website Hosting. It will show the website URL that will work.
Amazon S3 now supports Index Documents
The index document for a bucket can be set to something like index.html. When accessing the root of the site or a sub-directory containing a document of that name that document is returned.
It is extremely easy to do using the aws cli:
aws s3 website $MY_BUCKET_NAME --index-document index.html
You can set the index document from the AWS Management Console:
You can easily solve it by Amazon CloudFront link. At Amazon CloudFront you could modify the root object. You can download manager here: m1.mycloudbuddy.com/downloads.html.
Since It's been long time, this question being asked, and Amazon S3 changing their Interface. I would like to answer with updated screenshots.
We need to enable 'static web hosting' for S3 to serve as web hosting.
- Go to Properties -> click on static web hosting -> Select 'use this bucket to host a website'
- Enter the index document (index.html by default), error document and redirection rules, if any.
As answered in this answer on Stack Overflow, web hosting link would be: http://bucket-name.s3-website-region.amazonaws.com
I would suggest reading this thread from 2006 (On Amazon web services developers connection). It seems there's no easy solution to this.
Yes. using AWS Cloudfront lets you assign a default file.
you can do it using dns webforwards and cloaking. just forward to the complete path of the index.html
www.example.com forwards to http://www.example.com.s3.amazonaws.com and make sure you cloak the output.