0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【AWS】CLIでS3コマンドを使ってサーバに複数ファイルを配布する方法

Posted at

サーバに複数ファイルを配布する方法として、S3コマンドを使いました。

Ⅰ. AWSコンソール

①S3ファイル準備

S3にバケットを作成し、サーバに配布したいファイルをアップロードしておく。

②IAMユーザを作成

IAMユーザを作成し、下記のポリシーを直接アタッチする。
・AmazonS3ReadOnlyAccess

※作成後にcsvダウンロードして、
Access key ID、Secret access keyを取得しておく。

Ⅱ. CLI

①AWS CLIのインストール

awsコマンドを使用するため、CLIをインストールする。

curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"

sudo python get-pip.py

sudo pip install awscli

②認証情報の設定

aws configure

AWS Access Key ID [None]: **********
AWS Secret Access Key [None]: **********
Default region name [ap-northeast-1]: <Enter>
Default output format [None]: json

(下記ファイルに設定されます)

cat ~/.aws/config

cat ~/.aws/credentials

③S3コマンドの実行

まず、S3バケットの情報を取得できることを確認する。

aws s3 ls s3://<バケット名>/

同期させたいS3バケット名と、配布先として任意のディレクトリを指定する。

aws s3 sync s3://<バケット名>/ <任意のディレクトリ>

S3バケット内のファイルのみコピーしたい場合は、下記コマンドを実施する。

aws s3 cp s3://<バケット名>/ <任意のディレクトリ> --recursive

参考

【AWS】CLIの初期設定について(認証情報とコマンド補完)
AWS-CLIのsync機能でローカルファイルをS3に同期させる

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?