Linux command
aws-logs 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
List all log groups
aws logs describe-log-groups
List log streams
aws logs describe-log-streams --log-group-name [/aws/lambda/function-name]
Get log events
aws logs get-log-events --log-group-name [group_name] --log-stream-name [stream_name]
Tail logs
aws logs tail [/aws/lambda/function-name] --follow
Filter logs
aws logs filter-log-events --log-group-name [group_name] --filter-pattern "[ERROR]"
Create a log group
aws logs create-log-group --log-group-name [group_name]
Set retention policy
aws logs put-retention-policy --log-group-name [group_name] --retention-in-days [30]
Delete a log group
aws logs delete-log-group --log-group-name [group_name]
说明
aws logs is a subcommand of the AWS CLI that manages Amazon CloudWatch Logs, a service for monitoring, storing, and accessing log files from AWS resources and applications. Logs are organized into log groups (containers) and log streams (sequences of events from a single source). Log events contain a timestamp and raw message. Many AWS services like Lambda, ECS, and API Gateway automatically send logs to CloudWatch. CloudWatch Logs Insights enables SQL-like queries across log data. Metric filters extract metrics from log patterns. Subscription filters stream logs to Lambda, Kinesis, or Firehose in real-time.
参数
- describe-log-groups
- List log groups with metadata.
- create-log-group
- Create a new log group.
- delete-log-group
- Remove a log group and all its data.
- describe-log-streams
- List log streams in a group.
- get-log-events
- Retrieve log events from a stream.
- filter-log-events
- Search logs with a filter pattern.
- tail
- Stream logs in real-time (like tail -f).
- put-log-events
- Send log events to a stream.
- put-retention-policy
- Set log expiration period.
- delete-retention-policy
- Set logs to never expire.
- put-metric-filter
- Create a metric filter.
- put-subscription-filter
- Stream logs to another service.
- --log-group-name _name_
- Name of the log group.
- --log-stream-name _name_
- Name of the log stream.
- --filter-pattern _pattern_
- Pattern to match log events.
- --start-time _timestamp_
- Start time in milliseconds since epoch.
- --end-time _timestamp_
- End time in milliseconds since epoch.
- --follow
- Continuously stream new logs.
- --retention-in-days _days_
- Retention period (1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1096, 1827, 2192, 2557, 2922, 3288, 3653, or infinite).
FAQ
What is the aws-logs command used for?
aws logs is a subcommand of the AWS CLI that manages Amazon CloudWatch Logs, a service for monitoring, storing, and accessing log files from AWS resources and applications. Logs are organized into log groups (containers) and log streams (sequences of events from a single source). Log events contain a timestamp and raw message. Many AWS services like Lambda, ECS, and API Gateway automatically send logs to CloudWatch. CloudWatch Logs Insights enables SQL-like queries across log data. Metric filters extract metrics from log patterns. Subscription filters stream logs to Lambda, Kinesis, or Firehose in real-time.
How do I run a basic aws-logs example?
Run `aws logs describe-log-groups` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does describe-log-groups do in aws-logs?
List log groups with metadata.