IAM policy example: let S3 invoke a Lambda function, with a least privilege rewrite
Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.
A function resource policy that lets Amazon S3 invoke the function my-function for events from one bucket. The original checks the bucket ARN only. The rewrite adds the source account, because another account could own a bucket with the same name later.
Open the workbench ยท All examples
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3Invoke",
"Effect": "Allow",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Action": "lambda:InvokeFunction",
"Resource": "arn:aws:lambda:us-east-1:111122223333:function:my-function",
"Condition": {
"ArnLike": {
"AWS:SourceArn": "arn:aws:s3:::amzn-s3-demo-bucket"
}
}
}
]
}
What it allows
- Allows the S3 service to invoke the function when the event comes from the bucket amzn-s3-demo-bucket.
What it allows
Allow 1 action (lambda:InvokeFunction) on arn:aws:lambda:us-east-1:111122223333:function:my-function for Service s3.amazonaws.com when AWS:SourceArn ArnLike arn:aws:s3:::amzn-s3-demo-bucket.
Action or pattern Actions Access levels lambda:InvokeFunction1 Write 1
Checks
No flags from the six checks.
A bucket name can be reused after deletion, so the bucket ARN alone does not prove which account owns the bucket.
Least privilege rewrite
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "S3Invoke",
"Effect": "Allow",
"Principal": {
"Service": "s3.amazonaws.com"
},
"Action": "lambda:InvokeFunction",
"Resource": "arn:aws:lambda:us-east-1:111122223333:function:my-function",
"Condition": {
"ArnLike": {
"AWS:SourceArn": "arn:aws:s3:::amzn-s3-demo-bucket"
},
"StringEquals": {
"AWS:SourceAccount": "111122223333"
}
}
}
]
}
The rewrite adds AWS:SourceAccount so the bucket must belong to account 111122223333.
What it allows
Allow 1 action (lambda:InvokeFunction) on arn:aws:lambda:us-east-1:111122223333:function:my-function for Service s3.amazonaws.com when AWS:SourceArn ArnLike arn:aws:s3:::amzn-s3-demo-bucket and AWS:SourceAccount StringEquals 111122223333.
Action or pattern Actions Access levels lambda:InvokeFunction1 Write 1
Checks
No flags from the six checks.
Related pages
Sources
- AWS Lambda Developer Guide: resource-based policies, read 16 Nov 2026
- AWS Lambda Developer Guide: using Lambda with Amazon S3, read 16 Nov 2026
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026
Last reviewed 16 Nov 2026.