0
0
AWScloud~5 mins

Log groups and log streams in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you run applications or services, they create logs to record what happens. AWS CloudWatch organizes these logs into log groups and log streams to help you find and understand your logs easily.
When you want to collect logs from multiple servers or applications in one place.
When you need to separate logs by application or environment for easier management.
When you want to monitor logs in real time to detect errors or issues quickly.
When you want to keep logs organized by time or source for troubleshooting.
When you want to set up alerts based on specific log messages.
Commands
This command creates a new log group named 'my-app-logs' to hold related log streams.
Terminal
aws logs create-log-group --log-group-name my-app-logs
Expected OutputExpected
No output (command runs silently)
--log-group-name - Specifies the name of the log group to create
This command creates a log stream named 'app-server-1' inside the 'my-app-logs' log group to hold logs from one source.
Terminal
aws logs create-log-stream --log-group-name my-app-logs --log-stream-name app-server-1
Expected OutputExpected
No output (command runs silently)
--log-group-name - Specifies the log group where the stream will be created
--log-stream-name - Specifies the name of the log stream to create
This command lists all the log groups in your AWS account to verify that 'my-app-logs' was created.
Terminal
aws logs describe-log-groups
Expected OutputExpected
{"logGroups": [{"logGroupName": "my-app-logs", "creationTime": 1687000000000}]}
This command lists all log streams inside the 'my-app-logs' group to verify that 'app-server-1' exists.
Terminal
aws logs describe-log-streams --log-group-name my-app-logs
Expected OutputExpected
{"logStreams": [{"logStreamName": "app-server-1", "creationTime": 1687000000000}]}
--log-group-name - Specifies the log group to list streams from
Key Concept

If you remember nothing else from this pattern, remember: log groups organize logs by application or service, and log streams hold logs from individual sources within those groups.

Common Mistakes
Trying to create a log stream before creating its log group.
Log streams must belong to an existing log group, so the command fails if the group does not exist.
Always create the log group first, then create log streams inside it.
Using the wrong log group name when creating or listing log streams.
If the log group name is incorrect, AWS cannot find the group and the command fails or returns empty results.
Double-check the exact log group name before running commands involving it.
Summary
Create a log group to organize related logs together.
Create log streams inside the log group to separate logs from different sources.
Use describe commands to verify the creation and existence of log groups and streams.