Skip to content

Instantly share code, notes, and snippets.

@taesup
Forked from lorecrafting/s3deploy.md
Last active March 29, 2020 02:15
Show Gist options
  • Save taesup/d2d0b6fb08b4b7fcefad2c4f19297b63 to your computer and use it in GitHub Desktop.
Save taesup/d2d0b6fb08b4b7fcefad2c4f19297b63 to your computer and use it in GitHub Desktop.
S3 Deploy Notes

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: 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

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