IAMユーザを作成し、S3アクセスのポリシーを割り与える
EC2側では、aws configureで作成されたプロファイルを利用する
$ aws configure --profile test-s3 AWS Access Key ID [None]: ****************DMH2 AWS Secret Access Key [None]: ****************bHBU Default region name [None]: ap-northeast-1 Default output format [None]:
$ cat ~/.aws/config $ cat ~/.aws/credentials
$ aws s3 ls --profile test-s3
EC2にIAMロールを設定しておくことで、EC2からは特に設定せずに、S3にアクセスできるようになります。
Permittestbucket
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "arn:aws:s3:::*"
},
{
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::test-bucket"
},
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:AbortMultipartUpload",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::test-bucket/*"
}
]
}
Role : test-server1-role Policy : PermitS3
アクション > セキュリティ > IAMロールを変更
EC2にログイン後に、SSOのクレデンシャルを貼り付けると、ユーザに割り与えられているロール(ポリシー)でS3にアクセスできます。
Amazon S3は、容量無制限の安価なオブジェクトストレージ
一般向けサイト
ITエンジニア向けサイト
英語サイト
Portfolio
Copyright (c) 2025 クラウドのインフラ技術 All Rights Reserved.