Version: Policy language version (current version: 2012-10-17).Statement: Defines permissions.
Effect: Allow or Deny.Action: List of actions (API calls) allowed or denied.Resource: Identifies resources the policy applies to.AmazonS3ReadOnlyAccess.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:Get*", "s3:List*"],
"Resource": "*"
}
]
}
Principal element to specify the allowed requesters.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:Get*", "s3:List*"],
"Resource": [
"arn:aws:s3:::my_bucket"
]
"Sid": "Example",
"Principal": {
"AWS": [
"arn:aws:iam::123456789012:user/Alice"
]
},
}
]
}
! IAM groups cannot be used as a principal (important for certification exams).
arn:partition:service:region:account-id:resourcePartition: Group of AWS regions (e.g., AWS, AWS GovCloud, AWS China).Service: AWS product/service (e.g., IAM, S3, SQS).Region: AWS region (if applicable).Account ID: AWS account identifier.Resource: Specific resource identifier.arn:aws:iam::account-id:user/Alice (no region for IAM resources)arn:aws:iam::account-id:policy/db_adminarn:aws:s3:::my_bucketarn:aws:sqs:us-east-2:account-id:order-queueversion element.2012-10-17 (Do not change arbitrarily).Allow or Deny.* (wildcard).Deny statements)."Statement": [
{
"Effect": "Deny",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::my_bucket",
"arn:aws:s3:::my_bucket/*"
],
"Principal": "*",
"Condition": {
"NotIpAddress": {
"aws:SourceIp": "151.29.0.0/16"
}
}
}
]
"Statement": [
{
"Effect": "Deny",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::my_bucket",
"arn:aws:s3:::my_bucket/*"
],
"NotPrincipal": {
"AWS": [
"arn:aws:iam::123456789012:root",
"arn:aws:iam::123456789012:user/Admin" # Admins can still access from anywhere
]
}
"Condition": {
"StringNotEquals": {
"aws:sourceVpce": "vpce-1a2b3c4d" # each VPC endpoint has a unique ID
}
}
}
]
alice). Refer to Section 1.9 for how to create IAM users.aws configure --profile alice to set up Alice’s profile.aws s3 ls --profile alice to list S3 buckets.
AmazonS3ReadOnlyAccess permission to Alice. aws s3 cp text.txt s3://samil-demo --profile alice
bucket : samil-demo and samil-demo/*custom-s3-accessarn:aws:s3:::samil-demo,arn:aws:s3:::samil-demo/*ProjectAlpha ARN as a Principal to the policy.
"Principal": {
"AWS": "arn:aws:iam::587865868937:group/ProjectAlpha"
}
Invalid principal in policy. aws s3 ls s3://samil-demo --profile alice