# IAM policy: write to one CloudWatch Logs log group

IAM policy examples · Updated 17 November 2026

**Short answer:** Allow logs:CreateLogStream and logs:PutLogEvents on the log group ARN followed by :*, for example arn:aws:logs:eu-west-2:123456789012:log-group:/my-app/production:*. Add logs:CreateLogGroup only if the app creates its own group, and logs:DescribeLogStreams if your logging library asks for it.

## The policy

```
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "WriteToAppLogGroup",
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogStream",
        "logs:PutLogEvents",
        "logs:DescribeLogStreams"
      ],
      "Resource": "arn:aws:logs:eu-west-2:123456789012:log-group:/my-app/production:*"
    },
    {
      "Sid": "AppMetrics",
      "Effect": "Allow",
      "Action": "cloudwatch:PutMetricData",
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "cloudwatch:namespace": "MyApp"
        }
      }
    }
  ]
}
```

## How the ARN works

Log stream ARNs look like `…:log-group:/my-app/production:log-stream:i-0123456789abcdef0`. The pattern `log-group:/my-app/production:*` matches the group (which many APIs report with a trailing `:*`) and every stream inside it, so one resource covers both `CreateLogStream` (checked against the group) and `PutLogEvents` (checked against the stream).

- **WriteToAppLogGroup**: create streams, append events, and list streams, which older agents and some libraries call to find the right stream.
- **AppMetrics** (optional): the CloudWatch agent and embedded metric format libraries publish metrics with `PutMetricData`, which has no resource ARN. The `cloudwatch:namespace` condition limits it to your namespace.

## Attach it to an instance or task

```
aws iam put-role-policy --role-name my-app-ec2 \
  --policy-name write-logs --policy-document file://write-logs.json

aws logs describe-log-streams \
  --log-group-name /my-app/production \
  --order-by LastEventTime --descending --max-items 3
```

On EC2, the role reaches the agent through the instance profile; see [EC2 instance roles](https://cloudconsole.dev/iam/ec2-instance-role-s3). For the CloudWatch agent across many log groups, the managed `CloudWatchAgentServerPolicy` is simpler but grants writing to every log group in the account.

## Variations

- **Agent manages retention**: if the agent config sets `retention_in_days`, add `logs:PutRetentionPolicy` on the group.
- **App creates its group**: add `logs:CreateLogGroup` on `arn:aws:logs:eu-west-2:123456789012:log-group:/my-app/*`. Creating groups yourself (with retention set) is usually better than letting apps create groups that keep data forever.
- **Log group encrypted with KMS**: the writer needs no KMS permission; the key policy must allow the CloudWatch Logs service principal instead.
- **Several environments**: use `log-group:/my-app/*:*`, accepting that staging can then write into production's group.

## What failures look like

The CloudWatch agent writes its own log on the instance (on Linux, under `/opt/aws/amazon-cloudwatch-agent/logs/`). A missing permission appears there as an `AccessDeniedException` naming the action and the log group ARN, which tells you exactly which statement to fix. Application libraries usually log the same error to stderr.

```
aws iam simulate-principal-policy \
  --policy-source-arn arn:aws:iam::123456789012:role/my-app-ec2 \
  --action-names logs:PutLogEvents \
  --resource-arns arn:aws:logs:eu-west-2:123456789012:log-group:/my-app/production:log-stream:web-1
```

## Common mistakes

- **Group ARN without `:*`**: `CreateLogStream` works but `PutLogEvents` is denied, so streams appear with no events in them.
- **Agent running but no logs**: check the agent's own log on the instance first; it states AccessDenied plainly.
- **Using `logs:*`**: includes `DeleteLogGroup` and changing retention. A compromised host could erase its own trail.
- **Retention never set**: logs are kept forever by default. See [set log retention](https://cloudconsole.dev/how-to/set-cloudwatch-log-retention).

## Questions

### What permissions does an app need to write to CloudWatch Logs?

logs:CreateLogStream and logs:PutLogEvents on the log group ARN ending in :*, plus logs:CreateLogGroup if it creates the group.

### Why are my log streams empty?

The policy allows CreateLogStream on the group but PutLogEvents is denied, usually because the resource lacks the trailing :* that matches the stream ARNs.

## When this happens away from your desk

When an app goes quiet, check whether the log group stopped receiving events before assuming the app stopped. A phone that can tail a log group answers that in seconds.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [Amazon CloudWatch documentation](https://docs.aws.amazon.com/cloudwatch/)
- [Actions, resources, and condition keys for Amazon CloudWatch Logs](https://docs.aws.amazon.com/service-authorization/latest/reference/list_amazoncloudwatchlogs.html)

## Related

- [Lambda execution role: trust policy and basic permissions](https://cloudconsole.dev/iam/lambda-execution-role)
- [IAM policy: CloudWatch read-only for a monitoring tool](https://cloudconsole.dev/iam/cloudwatch-read-only)
- [How to set CloudWatch log retention](https://cloudconsole.dev/how-to/set-cloudwatch-log-retention)
- [aws logs describe-log-streams](https://cloudconsole.dev/cli/logs-describe-log-streams)
- [IAM role for an EC2 instance to access S3](https://cloudconsole.dev/iam/ec2-instance-role-s3)
- [ABAC: tag-based access control policy example](https://cloudconsole.dev/iam/abac-tags)

---

Source: https://cloudconsole.dev/iam/cloudwatch-logs-write

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
