LoginSignup
0
1

More than 1 year has passed since last update.

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

Last updated at Posted at 2021-10-17

はじめに

サーバーレスアプリのフロントエンドをS3でホストしていて、ビルドファイルのアップロードに使ったコマンドのメモ

目次

  1. アップロード手順
  2. おまけ
  3. 参考文献

1. アップロード手順

awscliをインストール & 設定 (awscliを使うのが初めての場合)

brew install awscli
aws configure

aws configure を実行するとアクセスキーとシークレットキーを聞かれるので自分のアカウントのキーを入力する

AWS上のS3バケットのリストを表示

aws s3 ls

設定がうまくいっているかと、自分がファイルをアップロードするS3バケットが存在するかどうか確認

アップロードしたいビルドファイルがあるフォルダーに移動

cd /dist

ファイルをアップロード

以下は /distフォルダーのすべてのアップロードするときの例

aws s3 sync . s3://BUCKET_NAME/ --include "*" --acl public-read --cache-control "max-age=3600”

2. おまけ

S3 + CloudFront + Route 53でフロントエンドアプリをホストしている場合は、ファイルのアップロードを反映させるために、CloudFrontのキャッシュを以下のコマンドでクリアする

aws cloudfront create-invalidation --distribution-id CLOUDFRONT_DISTRIBUTION_ID --paths "/*"

3. 参考文献

0
1
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
0
1