Should I host the static content of my webapp on A

2019-02-27 00:36发布

问题:

For a web app with a moderate amount of static media content which will be deployed on an Amazon EC2 instance, does it make sense to include the static content inside the war file or to host it on a separate S3 instance.

What will be the differences in terms of performance? What will be the differences in terms of service costs? What will be the differences in terms of complexity?

回答1:

Absolutely. For 4+ reasons:

  • Amazon S3 is almost management-free, so no hassles on provisioning, scaling, etc.
  • You will reduce EC2 server load
  • The storage is cheaper in S3 than in EC2 EBS volumes, as in S3 you only pay for what you consume, in EC2 you pay for the whole EBS provisioned storage (so there is some free space which you are paying for)
  • You could eventually add a CloudFront distribution to approach the static content to your users wherever they are (http://aws.amazon.com/cloudfront)
  • probably more ...

In terms of costs:

  • the data transfer from S3 to internet would be the same as you would pay on EC2
  • you will probably reduce the cost of the storage
  • you will have an additional cost for the number of requests made to your S3 files (http://aws.amazon.com/s3/#pricing)
  • on high traffic loads, you will also probably need less EC2 instances / resources (this is obviously not a fact, as it depends 100% on your app)

You will also have an overhead of complexity when releasing a new version of the app, because besides deploying it into the EC2 instances, you will also have to upload the new static file versions to S3. But you could automate this with a pretty simple script.