Amazon CloudFront
Developer Guide (API Version 2014-01-31)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Using CloudFront with Amazon S3

If you currently distribute content from your Amazon S3 bucket using a CNAME, you can migrate to CloudFront with no disruption by using the following process.

If your objects are stored in Amazon S3, you can either have your users get your objects directly from your Amazon S3 bucket, or you can configure CloudFront to get your objects from Amazon S3 and have your users get your objects from CloudFront.

If your users access your objects frequently, you can lower the cost of delivering your objects by adding CloudFront because, at higher usage, the price for CloudFront data transfer is lower than the price for Amazon S3 data transfer. In addition, downloads are faster with CloudFront than with Amazon S3 alone because your objects are stored closer to your users.

Important

CloudFront does not currently support Amazon S3 cross-origin resource sharing (CORS).

If you currently distribute content directly from your Amazon S3 bucket using your own domain name (such as example.com) instead of the domain name of your Amazon S3 bucket (such as MyAWSBucket.s3.amazonaws.com), you can add CloudFront with no disruption by using the following process.

Process for Adding CloudFront When You're Already Distributing Your Content from Amazon S3

  1. Create a CloudFront distribution using the process described in the applicable topic:

    When you create the distribution, specify the name of your Amazon S3 bucket as the origin server.

    Important

    For your bucket to work with CloudFront, the name must conform to DNS naming requirements. For more information, go to Bucket Restrictions and Limitations in the Amazon Simple Storage Service Developer Guide.

    If you're using a CNAME with Amazon S3, specify the CNAME for your distribution, too.

  2. Create a test web page that contains links to publicly readable objects in your Amazon S3 bucket, and test the links. For this initial test, use the CloudFront domain name of your distribution in the object URLs, for example, http://d111111abcdef8.cloudfront.net/images/image.jpg.

    For more information about format of CloudFront URLs, see Format of URLs for CloudFront Objects.

  3. If you're using Amazon S3 CNAMEs, your application uses your domain name (for example, example.com) to reference the objects in your Amazon S3 bucket instead of using the name of your bucket (for example, myawsbucket.s3.amazonaws.com). To continue using your domain name to reference objects instead of using the CloudFront domain name for your distribution (for example, d111111abcdef8.cloudfront.net), you need to update your settings with your DNS service provider.

    For Amazon S3 CNAMEs to work, your DNS service provider has a CNAME resource record set for your domain that currently routes end-user queries for the domain to your Amazon S3 bucket. When someone requests the object:

    http://example.com/images/image.jpg

    the request is automatically rerouted, and the object they see is:

    http://myawsbucket.s3.amazonaws.com/images/image.jpg

    To route queries to your CloudFront distribution instead of your Amazon S3 bucket, you need to use the method provided by your DNS service provider to update the CNAME resource record set for your domain. This updated CNAME record will start to redirect DNS queries from your domain to the CloudFront domain name for your distribution. For more information, see the documentation provided by your DNS service provider.

    Note

    If you're using Amazon Route 53 as your DNS service, go to Creating, Changing, and Deleting Resource Record Sets for information about how to update a CNAME resource record set.

    For more information about using CNAMEs with CloudFront, see Using Alternate Domain Names (CNAMEs).

    After you update the CNAME resource record set, it can take up to 72 hours for the change to propagate throughout the DNS system, although it usually happens faster. During this time, some requests for your content will continue to be routed to your Amazon S3 bucket, and others will be routed to CloudFront.