# IAM policy example: let a Lambda function write logs, with a least privilege rewrite

Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.

Gives a Lambda execution role the CloudWatch Logs actions needed to create its log group and stream and write events. The original allows logs:* on every log group. The rewrite names the function's own log group and three actions. Resource names and account 111122223333 are placeholders used in AWS documentation.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Logs",
      "Effect": "Allow",
      "Action": "logs:*",
      "Resource": "*"
    }
  ]
}
```

## What it allows

- Allows every CloudWatch Logs action on every log group and stream.

- Allows 133 actions (logs:*) on every resource.

Checks:
- high: Allows 70 write or permissions-management actions (2 permissions management) on every resource ("Resource": "*"). (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html)

The action logs:* covers 133 actions, including deleting log groups and reading other applications' logs.

## Least privilege rewrite

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "CreateGroup",
      "Effect": "Allow",
      "Action": "logs:CreateLogGroup",
      "Resource": "arn:aws:logs:us-east-1:111122223333:*"
    },
    {
      "Sid": "WriteLogs",
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/my-function:*"
    }
  ]
}
```

The rewrite lets the role create a group, then create streams and write events only in the log group named for the function.

- Allows 1 action (logs:CreateLogGroup) on arn:aws:logs:us-east-1:111122223333:*.
- Allows 2 actions (logs:CreateLogStream, logs:PutLogEvents) on arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/my-function:*.

Checks:
- No flags.

- [Paste it into the workbench](/)
- [Every CloudWatch Logs action and its access level](/actions/logs/)

## Related pages

- [IAM policy example: let Lambda poll one SQS queue](/examples/lambda-sqs-event-source-permissions/)
- [IAM policy example: read one DynamoDB table](/examples/dynamodb-read-one-table/)
- [IAM policy example: read and write one DynamoDB table](/examples/dynamodb-crud-one-table/)
- [All of them](/examples/)

## Sources

- AWS Lambda Developer Guide: permissions: https://docs.aws.amazon.com/lambda/latest/dg/lambda-permissions.html (read 16 Nov 2026)
- Amazon CloudWatch Logs User Guide: managing access: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/iam-access-control-overview-cwl.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-execution-role-write-logs/

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