LoginSignup
6
1

More than 5 years have passed since last update.

AWS CLI備忘録 S3バケット作成

Last updated at Posted at 2018-05-08

前提

  • AWS Cliがインストールされており、アプリケーションからコマンドが実行可能なこと
  • 実行環境にAWSアカウントのアクセスキーが設定されてること 'aws configure' で設定する必要あり
  • アクセスキーの取得元アカウントにS3の権限が付与されていること

S3バケット生成

https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/using-s3-commands.html
任意のバケット名で S3バケットを生成する
aws s3 mb s3://bucket-name

S3 バケット存在チェック

aws s3 ls s3://bucket-name

※作成直後だと空なので戻り値無し。
バケットが無いと以下のエラーが返る
An error occurred (NoSuchBucket) when calling the ListObjects operation: The specified bucket does not exist

S3バケット ウェブホスティング設定

ウェブホスティングの設定はポリシーではなく以下のコマンド
aws s3 website s3://bucket-name --index-document index.html

S3バケット ポリシー設定

ウェブホスティングのポリシー適用
```
aws s3api put-bucket-policy --bucket bucket-name --policy file://policy.json

policy.json:
{
"Version":"2012-10-17",
"Statement":[{
"Sid":"PublicReadGetObject",
"Effect":"Allow",
"Principal": "",
"Action":["s3:GetObject"],
"Resource":["arn:aws:s3:::bucket-name/
"]
}]
}
```

以後、CloudFrontのディストリビューション作成、Route53の登録までCLIで実行してみる。

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