<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wayne Pan &#187; aws</title>
	<atom:link href="http://waynepan.com/tag/aws/feed/" rel="self" type="application/rss+xml" />
	<link>http://waynepan.com</link>
	<description>tech &#124; js &#124; ui &#124; ajax &#124; mobile</description>
	<lastBuildDate>Mon, 17 Oct 2011 20:52:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Taking Full Advantage of CloudFront</title>
		<link>http://waynepan.com/2008/11/23/taking-full-advantage-of-cloudfront/</link>
		<comments>http://waynepan.com/2008/11/23/taking-full-advantage-of-cloudfront/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 06:11:11 +0000</pubDate>
		<dc:creator>Wayne</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[aws]]></category>

		<guid isPermaLink="false">http://waynepan.com/?p=289</guid>
		<description><![CDATA[We (AdMob) are exploring Amazon&#8217;s new AWS service CloudFront which is a simple CDN. Amazon built this services as a true CDN that people could use instead of using S3 what it wasn&#8217;t meant for. There&#8217;s a few things I&#8217;ve &#8230; <a href="http://waynepan.com/2008/11/23/taking-full-advantage-of-cloudfront/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We (AdMob) are exploring Amazon&#8217;s new AWS service <a href="http://aws.amazon.com/cloudfront/">CloudFront</a> which is a simple CDN. Amazon built this services as a true CDN that people could use instead of using S3 what it wasn&#8217;t meant for. </p>
<p>There&#8217;s a few things I&#8217;ve discovered about CloudFront that bear repeating here. These points are important if you&#8217;re attempting to use CloudFront to serve up static portions of your website.</p>
<ul>
<li>CloudFront pulls from S3 <b>only</b> if the CF node doesn&#8217;t already have a local copy. This means that the only way to push out a new file is to change the filename. (style.v1.css, styles.v2.css, etc.) This means that your framework will have to take advantage of this. Without file versioning you&#8217;re at risk of serving stale files from different nodes on CloudFront.</li>
<li>CloudFront doesn&#8217;t automatically detect if a browser accepts gzip encoding. You will have to keep separate versions of gzip files (and upload them pre-gzipped). The easiest way to do this is to keep a separate CNAME, eg static.domain.com and staticu.domain.com (u for uncompressed). Your website will then detect the <i>Accept-Encoding</i> header from the client and serve up the appropriate file. Gzipping could decrease your static content by 75% which not only speeds things up for your users but decrease your CloudFront costs.</li>
<li>You should set the appropriate headers when uploading content to S3. That means setting a far futures <i>Expires Header</i> and a <i>Cache-Control</i> header. You can read more about these <a href="http://developer.yahoo.com/performance/rules.html#expires">here</a>. There are two GUI programs that allow you to do this, <a href="http://www.bucketexplorer.com/">BucketExplorer</a> and <a href="http://jets3t.s3.amazonaws.com/index.html">jets3t</a>. If you want to write scripts, I would suggest ruby and the <a href="http://amazon.rubyforge.org/">AWS::S3</a> gem.</li>
</ul>
<p>Here is some ruby code to do what I&#8217;ve described above.</p>
<pre>
require 'rubygems'
require 'aws/s3'
require 'stringio'
require 'zlib'

AWS::S3::Base.establish_connection!(
  :access_key_id => '[key]',
  :secret_access_key => '[key]'
)

strio = StringIO.open('', 'w')
gz = Zlib::GzipWriter.new(strio)
gz.write(open('[file]').read)
gz.close
AWS::S3::S3Object.store('[s3 location]',
                        strio.string,
                        '[s3 bucket]',
                        :access => :public_read,
                        'Content-Encoding' => 'gzip',
                        'Content-Type' => 'application/x-javascript',
                        'Expires' => 'Fri, 16 Nov 2018 22:09:29 GMT') 
</pre>
]]></content:encoded>
			<wfw:commentRss>http://waynepan.com/2008/11/23/taking-full-advantage-of-cloudfront/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

