I am trying to provide general access to a bucket using an S3 bucket policy, while also allowing specific access to a role using a role policy. The role is used by a Lambda function to handle objects in the bucket. It is being stopped at the first hurdle - it cannot GET anything with the prefix "incoming/", even though it is allowed in the role policy, and not explicitly denied in the bucket policy.
Role Policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowBucketPut",
"Effect": "Allow",
"Action": [
"s3:PutObject"
],
"Resource": "arn:aws:s3:::bucket-name/*"
},
{
"Sid": "AllowIncomingGetDelete",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::bucket-name",
"Condition": {
"StringLike": {
"s3:prefix": "incoming/*"
}
}
}
]
}
Note: I also tried removing the condition and changing the resource to "arn:aws:s3:::bucket-name/incoming*", which only seemed to change how the policy simulator behaved. Another note: GET from the bucket with "incoming/*" prefix does work in the simulator, just not in practice.
I have not removed any statements in the below bucket policy, as I am not sure what might be relevant. IP addresses have been omitted.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowPublicList",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::bucket-name",
"Condition": {
"StringLike": {
"s3:prefix": "public*"
}
}
},
{
"Sid": "AllowPublicGet",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket-name/public*"
},
{
"Sid": "AllowPrivateList",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::bucket-name",
"Condition": {
"StringLike": {
"s3:prefix": "private*"
},
"IpAddress": {
"aws:SourceIp": [
"..."
]
}
}
},
{
"Sid": "AllowPrivateGet",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::bucket-name/private*",
"Condition": {
"IpAddress": {
"aws:SourceIp": [
"..."
]
}
}
},
{
"Sid": "AllowIncomingPut",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::bucket-name/incoming*",
"Condition": {
"IpAddress": {
"aws:SourceIp": [
"..."
]
}
}
}
]
}
Apologies for the wall of text.
I don't understand why my role is not able to GET objects with the prefix "incoming/".
The Lambda function is getting 403 access denied when doing the following:
S3.download_file(bucket, key, localfile)