Skip to content

Instantly share code, notes, and snippets.

@JimzyLui
Forked from lorecrafting/s3deploy.md
Last active February 7, 2019 03:52
Show Gist options
  • Save JimzyLui/fb86bea1762dd0c84e4e99ef1aa19ad7 to your computer and use it in GitHub Desktop.
Save JimzyLui/fb86bea1762dd0c84e4e99ef1aa19ad7 to your computer and use it in GitHub Desktop.
S3 Deploy Notes

Deploying to AWS S3

Prequisites: AWS Account

In AWS Console:

  1. Go to IAM Service and create new group, name it S3FullAccessGroup, attach the AmazonS3FullAccess policy to it.
  2. In IAM Service, add new user. Name it something like yourName_macbookpro_cli. Make sure only programmatic access is checked off. Add the user to the S3FullAccessGroup.
  3. When done with wizard, it will give you your secret access key only ONCE. Don't leave this page yet.

In Local Development Terminal:

  1. OSX: brew install awscli
    Linux: sudo apt update sudo apt install awscli
  2. aws configure
  3. Enter Access Key Id
  4. Enter Secret Access Key
  5. Set default region to us-west-2 (or whatever region you want the cli to default to)
  6. Just press enter when it asks for default output format.

Create new S3 bucket that's public, read only (no caps in bucket name allowed):
aws s3api create-bucket --bucket {my-bucket} --acl public-read --region us-west-2 --create-bucket-configuration LocationConstraint=us-west-2

Configure bucket to serve static website (bucketnames have to be lowercase):
aws s3 website s3://{my-bucket}/ --index-document index.html --error-document index.html

Upload all files in current directory excluding .git folder and apply public-read permissions to all files:
aws s3 sync . s3://{my-bucket} --delete --acl public-read --exclude '.git*'

Delete all files in bucket:
aws s3 rm --recursive s3://{my-bucket}

Delete entire bucket and contents:
aws s3 rb s3://{bucket-name} --force

Navigate to:
http://{my-bucket}.s3-website-us-west-2.amazonaws.com

Can create a batch file to refresh the contents:
touch {batchFileName}

Add the code inside the batch file...

Change the batch file permissions so it can be executed/run:
chmod 755 {batchFileName}

Run the batch file:
./{batchFileName}

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