# 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.

```json
{
  "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.

- Allows 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.

Checks:
- No flags.

A bucket name can be reused after deletion, so the bucket ARN alone does not prove which account owns the bucket.

## Least privilege rewrite

```json
{
  "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.

- Allows 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.

Checks:
- No flags.

- [Paste it into the workbench](/)
- [Every Lambda action and its access level](/actions/lambda/)

## Related pages

- [IAM policy example: SNS topic policy for alarms](/examples/sns-topic-policy-allow-cloudwatch-alarms/)
- [IAM policy example: ECR policy for cross-account pull](/examples/ecr-repository-policy-cross-account-pull/)
- [IAM policy example: read one S3 bucket](/examples/s3-read-one-bucket/)
- [All of them](/examples/)

## Sources

- AWS Lambda Developer Guide: resource-based policies: https://docs.aws.amazon.com/lambda/latest/dg/access-control-resource-based.html (read 16 Nov 2026)
- AWS Lambda Developer Guide: using Lambda with Amazon S3: https://docs.aws.amazon.com/lambda/latest/dg/with-s3-example.html (read 16 Nov 2026)
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026): https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://iampolicygenerator.com/examples/lambda-resource-policy-allow-s3-invoke/

This site is not affiliated with Amazon Web Services. AWS service and product names are used only to describe AWS services.
