Skip to content

Instantly share code, notes, and snippets.

@sscotth
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sscotth/087e121bc036c58fd057 to your computer and use it in GitHub Desktop.
Save sscotth/087e121bc036c58fd057 to your computer and use it in GitHub Desktop.
S3 Hosting with S3-CLI

S3 Hosting notes

Install s3cmd

OSX: brew install s3cmd
Debian/Ubuntu: apt-get install s3cmd
Other: Download from http://s3tools.org/s3cmd

use s3cmd to create your .s3cfg config file

s3cmd --configure

Install S3-CLI

npm install -g s3-cli

Note: can use s3cmd for this, but the commands may be slightly different

Create AWS user and save credentials

Access Key ID: AKIAXXXXXXXXXXXXMLSQ

Secret Access Key: W27ZXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXQ3MG

Save bucket's ARN code

ARN: arn:aws:s3:::omgttt.sscotth.io/*

Note: The ending /* refers to all keys or objects/files inside the bucket

Add AWS user permissions

Edit the Resource item to match your bucket

List available buckets (needed for S3-CLI's test script)

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1419003855000",
      "Effect": "Allow",
      "Action": [
        "s3:ListAllMyBuckets"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}

GET, POST, PUT, and DELETE permisssions plus the ability to make items public

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1419003855000",
      "Effect": "Allow",
      "Action": [
        "s3:DeleteObject",
        "s3:PutObject",
        "s3:GetObject",
        "s3:PutObjectAcl"
      ],
      "Resource": [
        "arn:aws:s3:::omgttt.sscotth.io/*"
      ]
    }
  ]
}

List Items inside bucket

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1419005861000",
      "Effect": "Allow",
      "Action": [
        "s3:GetBucketLocation",
        "s3:ListBucket"
      ],
      "Resource": [
        "arn:aws:s3:::omgttt.sscotth.io"
      ]
    }
  ]
}

Test command line interface

s3-cli ls s3://omgttt.sscotth.io/
s3-cli del s3://omgttt.sscotth.io/404.html
s3-cli put 404.html s3://omgttt.sscotth.io/404.html
s3-cli sync --delete-removed -P . s3://omgttt.sscotth.io/

Add the deploy script to project's package.json

"deploy": "s3-cli sync --delete-removed -P . s3://omgttt.sscotth.io/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment