Bird
Raised Fist0
AWScloud~10 mins

Log groups and log streams in AWS - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a CloudWatch log group named 'MyAppLogs'.

AWS
resource "aws_cloudwatch_log_group" "example" {
  name = [1]
}
Drag options to blanks, or click blank then click option'
A"MyAppStream"
B"MyAppLogs"
C"AppLogGroup"
D"LogGroup1"
Attempts:
3 left
💡 Hint
Common Mistakes
Using a log stream name instead of a log group name.
Forgetting to put quotes around the name.
2fill in blank
medium

Complete the code to create a CloudWatch log stream named 'AppStream' inside the log group 'MyAppLogs'.

AWS
resource "aws_cloudwatch_log_stream" "example" {
  name           = [1]
  log_group_name = "MyAppLogs"
}
Drag options to blanks, or click blank then click option'
A"LogStream"
B"Stream1"
C"MyAppLogs"
D"AppStream"
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing log group name with log stream name.
Using the wrong quotes or missing quotes.
3fill in blank
hard

Fix the error in the code to correctly reference the log group name in the log stream resource.

AWS
resource "aws_cloudwatch_log_stream" "example" {
  name           = "AppStream"
  log_group_name = [1]
}
Drag options to blanks, or click blank then click option'
Aaws_cloudwatch_log_group.example.name
B"aws_cloudwatch_log_group.example.name"
Caws_cloudwatch_log_group.example
D"MyAppLogs"
Attempts:
3 left
💡 Hint
Common Mistakes
Putting quotes around the resource reference, making it a string literal.
Referencing the whole resource instead of its name attribute.
4fill in blank
hard

Fill both blanks to create a log group and a log stream with correct names.

AWS
resource "aws_cloudwatch_log_group" "app_logs" {
  name = [1]
}

resource "aws_cloudwatch_log_stream" "app_stream" {
  name           = [2]
  log_group_name = aws_cloudwatch_log_group.app_logs.name
}
Drag options to blanks, or click blank then click option'
A"AppLogGroup"
B"AppStream1"
C"StreamMain"
D"LogGroupMain"
Attempts:
3 left
💡 Hint
Common Mistakes
Using the same name for both log group and log stream.
Forgetting quotes around the names.
5fill in blank
hard

Fill all three blanks to define a log group, a log stream, and assign the log stream to the group correctly.

AWS
resource "aws_cloudwatch_log_group" "main_logs" {
  name = [1]
}

resource "aws_cloudwatch_log_stream" "main_stream" {
  name           = [2]
  log_group_name = [3]
}
Drag options to blanks, or click blank then click option'
A"MainLogGroup"
B"MainStream"
Caws_cloudwatch_log_group.main_logs.name
D"MainLogStream"
Attempts:
3 left
💡 Hint
Common Mistakes
Quoting the resource reference for log_group_name.
Mixing up log stream and log group names.

Practice

(1/5)
1. What is the main purpose of a log group in AWS CloudWatch Logs?
easy
A. To organize multiple log streams into a single container
B. To store individual log events directly
C. To control user access to AWS services
D. To monitor AWS billing and cost usage

Solution

  1. Step 1: Understand log group role

    A log group acts as a container for multiple log streams, grouping logs by application or resource.
  2. Step 2: Differentiate from other options

    Log events are stored in log streams, not directly in log groups. Access control and billing are unrelated.
  3. Final Answer:

    To organize multiple log streams into a single container -> Option A
  4. Quick Check:

    Log group = container for log streams [OK]
Hint: Log groups hold streams, streams hold logs [OK]
Common Mistakes:
  • Confusing log groups with log streams
  • Thinking logs are stored directly in log groups
  • Mixing log groups with access control or billing
2. Which of the following is the correct way to create a log stream named appStream inside a log group appGroup using AWS CLI?
easy
A. aws logs create-log-group --log-stream-name appStream --log-group-name appGroup
B. aws logs create-log-stream --name appStream --group appGroup
C. aws logs create-log-stream appGroup appStream
D. aws logs create-log-stream --log-group-name appGroup --log-stream-name appStream

Solution

  1. Step 1: Identify correct AWS CLI command syntax

    The command to create a log stream is aws logs create-log-stream with parameters --log-group-name and --log-stream-name.
  2. Step 2: Verify aws logs create-log-stream --log-group-name appGroup --log-stream-name appStream matches syntax

    aws logs create-log-stream --log-group-name appGroup --log-stream-name appStream correctly uses the command and parameters in the right order and names.
  3. Final Answer:

    aws logs create-log-stream --log-group-name appGroup --log-stream-name appStream -> Option D
  4. Quick Check:

    Correct CLI syntax = aws logs create-log-stream --log-group-name appGroup --log-stream-name appStream [OK]
Hint: Remember: create-log-stream needs both group and stream names [OK]
Common Mistakes:
  • Using create-log-group instead of create-log-stream
  • Swapping parameter names
  • Omitting required flags
3. Given the following AWS CLI commands executed in order:
aws logs create-log-group --log-group-name myAppLogs
aws logs create-log-stream --log-group-name myAppLogs --log-stream-name stream1
aws logs put-log-events --log-group-name myAppLogs --log-stream-name stream1 --log-events '[{"timestamp":1609459200000,"message":"Start"}]'
aws logs describe-log-streams --log-group-name myAppLogs

What will the describe-log-streams command output include?
medium
A. A list containing one log stream named 'stream1' with stored events
B. An empty list because no log streams exist yet
C. An error stating the log group does not exist
D. A list of all log groups in the account

Solution

  1. Step 1: Trace commands creating log group and stream

    The first two commands create a log group 'myAppLogs' and a log stream 'stream1' inside it.
  2. Step 2: Put log event and describe streams

    The third command adds a log event to 'stream1'. The last command lists streams in 'myAppLogs', so it will show 'stream1' with events.
  3. Final Answer:

    A list containing one log stream named 'stream1' with stored events -> Option A
  4. Quick Check:

    Created stream appears in describe output [OK]
Hint: Create group and stream before putting logs [OK]
Common Mistakes:
  • Expecting empty list before adding streams
  • Confusing log groups with streams in output
  • Assuming describe lists groups, not streams
4. You run this AWS CLI command:
aws logs put-log-events --log-group-name myGroup --log-stream-name myStream --log-events '[{"timestamp":1609459200000,"message":"Hello"}]'

But you get an error saying the log stream does not exist. What is the most likely fix?
medium
A. Remove the timestamp from the log event
B. Change the log group name to an existing group
C. Create the log stream 'myStream' inside 'myGroup' before putting events
D. Use the create-log-group command instead

Solution

  1. Step 1: Understand error cause

    The error indicates the log stream 'myStream' does not exist in 'myGroup'. You must create the stream before sending logs.
  2. Step 2: Identify correct fix

    Creating the log stream with aws logs create-log-stream resolves the error. Changing group or removing timestamp won't help.
  3. Final Answer:

    Create the log stream 'myStream' inside 'myGroup' before putting events -> Option C
  4. Quick Check:

    Log stream must exist before putting logs [OK]
Hint: Create log stream first to avoid put-log-events error [OK]
Common Mistakes:
  • Trying to put logs before stream creation
  • Ignoring error details about missing stream
  • Confusing log group creation with stream creation
5. You want to organize logs from multiple microservices in AWS CloudWatch. Each microservice should have its own log stream, but all streams must be grouped for easy management and retention. Which setup is best?
hard
A. Store logs outside CloudWatch to avoid managing groups and streams
B. Create one log group for all microservices, and create separate log streams for each microservice inside it
C. Create one log group per microservice and put all logs in a single stream inside each group
D. Create one log stream per microservice without using log groups

Solution

  1. Step 1: Understand grouping and streaming roles

    Log groups organize logs for management and retention. Log streams separate logs by source within groups.
  2. Step 2: Choose best structure for microservices

    Using one log group for all microservices and separate streams per microservice allows easy management and searching.
  3. Step 3: Evaluate other options

    Create one log stream per microservice without using log groups lacks grouping, C creates many groups complicating retention, A ignores CloudWatch benefits.
  4. Final Answer:

    Create one log group for all microservices, and create separate log streams for each microservice inside it -> Option B
  5. Quick Check:

    Group = container; streams = sources [OK]
Hint: Group logs by app, stream by source inside group [OK]
Common Mistakes:
  • Skipping log groups and using only streams
  • Creating too many log groups unnecessarily
  • Ignoring CloudWatch log management features
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard