8 February 2017

Publish Directly to S3

Author a static Web site locally in hexo, and publish directly to a Amazon Web Services’ S3 bucket. You’ll use hexo, a text editor, and the AWS CLI.

Prerequisites

$ npm install -g hexo-cli
$ pip install awscli
$ aws configure
AWS Access Key ID [None]: <Valid Value>
AWS Secret Access Key [None]: <Valid Value>
Default region name [None]: <Valid Value>
Default output format [None]:
$ aws s3 ls
2015-03-09 00:34:31 yourfirstbucket
2015-03-09 03:41:21 bucket-for-logs
2015-03-09 15:03:30 yourwebsite.com
2015-03-09 14:55:14 www.yourwebsite.com
$ aws s3api get-bucket-website --bucket yourwebsite.com
{
    "IndexDocument": {
        "Suffix": "index.html"
    },
    "ErrorDocument": {
        "Key": "error.html"
    }
}

Author a static site in hexo

Initialize the local directory for your hexo site

$ mkdir ~/yourwebsite.com
$ cd ~/yourwebsite.com
$ hexo init .
$ hexo new draft "My New Article"
INFO  Created: ~/yourwebsite.com/source/_drafts/My-New-Article.md
$ hexo server --drafts --open

Edit the draft with your text editor, save, and refresh browser to view

Publish the draft, and generate the site content with hexo

<CTRL-C to stop the hexo server>
$ hexo publish 'My-New-Article'
$ hexo generate
$ ls public
2017		css		index.html
archives	fancybox	js

Publish directly to S3

$ aws s3 sync public/ s3://yourwebsite.com/ --delete --sse
comments? | contribute | tags: notes