Search code examples
amazon-web-servicesnginxamazon-ec2amazon-cloudfront

AWS - Serving static files with performance in mind


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?


Solution

  • 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.