Setting Up Octopress with Amazon Web Services

When I initially had the idea to start a blog, I was looking up how to set up WordPress with Amazon Web Services (AWS) - the web host I decided to use. Somehow, I ended up stumbling into Jekyll, which later led me to Octopress. The post describes the steps needed to set up Octopress with AWS.

There are lots of posts out in the internets that describe other people’s experiences with Octopress. Here are a few…


So how do we get octopress set up with AWS?

Step 1: Install Octopress

Follow the instructions here: http://octopress.org/docs/setup/

Step 2: Install s3_website

s3_website is a tool used to upload your octopress blog to Amazon S3 (an Amazon Web Service used for web storage). For more information on s3_website, go here: https://github.com/laurilehmijoki/s3_website

In the terminal, enter the following commands:

cd <octopress_blog>
gem install s3_website
s3_website cfg create  # creates s3_website.yl (configuration file)

Step 3: Create User in AWS IAM

AWS IAM (Identity and Access Management) is used to manage access to your resources in AWS. In this step, we’ll create a user in IAM that will be used by s3_website.

  1. Go to https://aws.amazon.com/
  2. Click My Account / Console on the top-right of the window and select AWS Management Console
  3. Click Services at the top-left of the window and select IAM
  4. Click Users on the left
  5. Click Create New Users
  6. Enter a username and click Create
  7. Expand the Show User Security Credentials and copy the Access Key ID and Secret Access Key. Alternatively, you can click Download Credentials to save a text file containing the two keys.

Step 4: Configure s3_website

s3_website requires the keys that were obtained in IAM.

  1. Open /s3_website.yml in a text editor
  2. Under s3_id, enter the Access Key Id
  3. Under s3_secret, enter the Secret Access Key
  4. Under s3_bucket, enter the name of the S3 bucket (e.g. mywebsite.com)
  5. Save the file

Step 5: Configure Octopress for s3_website

_config.yml

By default, octopress will generate blog files to a directory named public. s3_website currently expects these files to be in _site.

Open /_config.yml and set...

destination: _site

config.rb

Change compass to generate the CSS files to the new destination (_site).

Open /config.rb and set...

css_dir = "_site/stylesheets"

Support “bundle exec rake preview” command

Open /Rakefile and set...

public_dir = "_site"

Open /config.ru and change references of *public* to *_site*...

...
not_found do
  send_file(File.join(File.dirname(__FILE__), '_site', '404.html'), {:status => 404})
end

def send_sinatra_file(path, &missing_file_block)
  file_path = File.join(File.dirname(__FILE__), '_site',  path)
  file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i
  File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
end
...

Step 6: Test s3_website

In the terminal, enter the following commands:

cd <octopress_blog>
rake generate
s3_website push  # pushes website files to s3 bucket

Check mywebsite.com to see if the changes were successful!

References