https://dev.classmethod.jp/articles/s3-request-https-only/
https://aws.amazon.com/jp/premiumsupport/knowledge-center/s3-bucket-policy-for-config-rule/
-- 1. コマンド等のインストール
-- 1.1 aws cli version 2 インストール
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
-- 1.2 jqインストール
sudo yum -y install jq
-- 2. S3 バケットを作成する
aws s3 ls
aws s3 mb s3://bucket123
-- 3. バケットポリシーの設定
{
"Id": "ExamplePolicy",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowSSLRequestsOnly",
"Action": "s3:*",
"Effect": "Deny",
"Resource": [
"arn:aws:s3:::bucket123",
"arn:aws:s3:::bucket123/*"
],
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
},
"Principal": "*"
}
]
}
aws s3api put-bucket-policy \
--bucket bucket123 \
--policy file://b.json
aws s3api get-bucket-policy \
--bucket bucket123
-- 4. 動作確認
echo test > test.txt
aws s3 cp test.txt s3://bucket123 --endpoint-url http://s3.ap-northeast-1.amazonaws.com
aws s3 cp test.txt s3://bucket123 --endpoint-url https://s3.ap-northeast-1.amazonaws.com
aws s3 cp test.txt s3://bucket123
aws s3 ls s3://bucket123 --recursive --endpoint-url http://s3.ap-northeast-1.amazonaws.com
aws s3 ls s3://bucket123 --recursive --endpoint-url https://s3.ap-northeast-1.amazonaws.com
aws s3 ls s3://bucket123 --recursive
aws s3 cp s3://bucket123/test.txt . --endpoint-url http://s3.ap-northeast-1.amazonaws.com
aws s3 cp s3://bucket123/test.txt . --endpoint-url https://s3.ap-northeast-1.amazonaws.com
aws s3 cp s3://bucket123/test.txt .
httpを指定した場合エラーとなる
-- 5. クリーンアップ
-- バケットの削除
aws s3 ls
aws s3 rb s3://bucket123 --force