Here is something you can try:
Create Role:
aws iam create-role --role-name <PerfTest-EC2-Role-Name> --assume-role-policy-document '{"Version":"2012-10-17","Statement":[{"Sid":"","Effect":"Allow","Principal":{"Service": "ec2.amazonaws.com"},"Action":"sts:AssumeRole"}]}'
Add Role to EC2 Instance Profile:
aws iam add-role-to-instance-profile --instance-profile-name <JMeter-EC2-InstanceProfile-ID> --role-name <PerfTest-EC2-Role-Name>
Grant the Role S3 permissions:
cat << EOF > BucketPolicy.json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": "arn:aws:s3:::<Bucket-Name>/*"
},
{
"Sid": "ServiceRoleWriteObject",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<Client-ID>:role/<PerfTest-EC2-Role-Name>"
},
"Action": [
"s3:DeleteObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::<Bucket-Name>/*"
}
]
}
EOF
aws s3api put-bucket-policy --bucket <Bucket-Name> --policy file://BucketPolicy.json
If 2. above fails with
Cannot exceed quota for InstanceSessionsPerInstanceProfile: 1
you can look at this answer.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…