135
136

More than 5 years have passed since last update.

AWS CLI で S3 にファイルをアップロード

Last updated at Posted at 2015-07-06

awscli のインストール

brewでインストール

brew install awscli

pipでインストール

$ sudo pip install awscli

pipが無いとき

$ sudo easy_install pip

バージョンの確認

$ aws --version

AWSのセットアップ

regionとoutput formatは大概固定でいいんじゃないかと。
ap-northeast-1は東京

$ aws configure --profile=PROFILE_NAME
AWS Access Key ID [None]: myaccesskey
AWS Secret Access Key [None]: mysecretkey
Default region name [None]: ap-northeast-1
Default output format [None]: json

S3のバケット一覧出力

$ aws s3 ls --profile=PROFILE_NAME

ファイルのアップロード

ファイルを個別にアップロード

$ aws s3 cp sample.txt s3://mybucketname/ --acl public-read --profile=PROFILE_NAME

ファイルをまとめてアップロード

$ aws s3 sync . s3://mybucketname/ --include "*" --acl public-read --cache-control "max-age=3600" --profile=PROFILE_NAME

HTMLファイルをまとめてアップロード

$ aws s3 sync . s3://mybucketname/ --exclude "*" --include "*.html" --acl public-read --cache-control "max-age=3600" --profile=PROFILE_NAME

gzip圧縮したhtml,js,cssをアップロード

aws s3 sync ./build s3://mybucketname/DIRECTORY_NAME/ --exclude "*" --include "*.js"\
  --acl public-read --cache-control "max-age=600" --content-type "application/javascript"\
  --content-encoding "gzip" --profile PROFILE_NAME
aws s3 sync ./build s3://mybucketname/DIRECTORY_NAME/ --exclude "*" --include "*.css"\
  --acl public-read --cache-control "max-age=600" --content-type "text/css"\
  --content-encoding "gzip" --profile PROFILE_NAME
aws s3 sync ./build s3://mybucketname/DIRECTORY_NAME/ --exclude "*" --include "*.html"\
  --acl public-read --cache-control "max-age=300" --content-type "text/html"\
  --content-encoding "gzip" --profile PROFILE_NAME

登録済みの情報を確認する

設定一覧

$ cat ~/.aws/config

アクセスキーとシークレット一覧

$ cat ~/.aws/credentials

参考

135
136
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
135
136