简体   繁体   中英

Statics deployment with AWS Elastic Beanstalk and AWS Cloudfront

I'm using AWS Elastic Beanstalk for deploying my PHP application, which is great because I can deploy the application with a single git push action. In this application I have static files such as JS and images.

Is there any automatic way to deploy these static files to Amazon Cloudfront? Of course I can write a deployment script but I want to know if someone is using any AWS provided solution.

You can specify your application URL as the origin for your Cloudfront distribution (rather than using a S3 bucket). This will make Cloudfront transparently start serving your static assets. A couple of caveats:

  1. You'll need to adjust the routes to your assets to use absolute URLs. For example <img src="/images/hello.png" /> will need to become <img src="//xxxxxx.cloudfront.net/images/hello.png" /> . (Note the odd-looking scheme. That allows the same URL to be used via both HTTP and HTTPS connections).

  2. You'll need to implement some type of resource versioning method so users are always getting the latest revisions. So <img src="//a42532.cloudfront.net/images/hello.png" /> actually becomes <img src="//a42532.cloudfront.net/images/hello-3456464234.png" /> (or something similar). Otherwise you will have to manually invalidate the distribution each time you update your static files, which takes forever and can get very costly since Amazon bills for invalidations. With Git, you could write a commit hook that adds the UNIX epoch to your assests' filenames before the code is pushed to Beanstalk.

You have a few options that all are around AWS/S3 related tools.

  • Check out the PHP SDK , which supports S3 and CloudFront. You can start with the following screencast .

  • Check out the option to host your static web site on S3 . Once it is hosted, it is easier to define CloudFront to serve your file from the Edge nodes.

  • Check out CloudBerry tool . It has a free version as well. it makes it very easy to manage files on S3, CloudFront and other storage related services.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM