AWS - Serving static files with performance in min

2019-03-06 11:28发布

问题:

I'm working on a project of mine and I'm expecting about ~500-750k unique pings per month.

I'm curious to hear if there's any better way (in terms of latency) to host a static website than my idea below.

Idea:

  • EC2 instance running NGINX with gzip enabled
  • CloudFront for CDN

What I'm hosting:

  • HTML (3 pages in total)
  • CSS
  • SVG/PNG images

Also, if my idea above is OK, which EC2 instance would you go for? I'm thinking a micro instance would do just fine, I don't see why I would need the extra RAM/CPU.

Edit: Or how about something simpler like S3 w/ CloudFront?

回答1:

Cost effective , high-available, fully managed , secure and fault-tolerant solution for your case is AWS S3 :

  1. Create S3 Bucket (mybucket) and enable website static properties on it.

  2. Create IAM user with a permission of read/write on that bucket.

        "Version": "2012-10-17",
        "Statement": [
          {
            "Action": "s3:ListAllMyBuckets",
            "Effect": "Allow",
            "Resource": "arn:aws:s3:::*"
          },
          {
            "Sid": "Stmt1487841624000",
            "Effect": "Allow",
            "Action": ["s3:*"],
            "Resource": ["arn:aws:s3:::mybucket/*", "arn:aws:s3:::mybucket"]
          }
        ]
        }
    

    (Keep secret key and access key and the region where you create the bucket)

  3. Configure your secret key and access key in your laptop

      aws configure;
    
  4. Then upload your static website :

      aws s3 sync /path/to/local/dir s3://mybucket; 
    

Congrats! your website is hosted : http://[BUCKETNAME].s3-website.[REGIONMAME].amazonaws.com

If you want to :

  • map the website to another domain

  • or/and use SSL

  • or/and integrate with WAF.

  • or/and so on...

Use also AWS CloudFront.



回答2:

Can I be late to the party and also suggest S3. Here are some metrics of actual performance

This is a graph showing S3 latency with a reasonably high load

As you can see the average time to first byte over each hour ranges from 30 to 60ms

We also found that the total amount of traffic did not affect the latency, in fact there seemed to be an inverse relationship between averaged latency and total request count. I assume this was due to autoscaling "under the hood" at the AWS end

According to AWS documentation the S3 part of the static website setup is good for 800 GET requests per second, see http://docs.aws.amazon.com/AmazonS3/latest/dev/request-rate-perf-considerations.html

Sorry I have no ngnix statistics to compare this with. We don't use ngnix for this type of workload