📖 Scenario: You are setting up logging for a simple application running on AWS. Logs help you see what is happening inside your app. AWS uses log groups to organize logs and log streams to hold the actual log entries.Think of a log group as a folder and log streams as files inside that folder. You want to create a log group and then add a log stream inside it.
🎯 Goal: Create an AWS CloudFormation template that defines a log group named MyAppLogGroup and a log stream named MyAppLogStream inside that log group.
📋 What You'll Learn
Create a CloudFormation resource for a log group named MyAppLogGroup
Create a CloudFormation resource for a log stream named MyAppLogStream
The log stream must be inside the MyAppLogGroup log group
Use valid AWS CloudFormation syntax for both resources
💡 Why This Matters
🌍 Real World
Logging is essential for monitoring and troubleshooting applications running on AWS. Organizing logs into groups and streams helps keep logs manageable and accessible.
💼 Career
Cloud engineers and DevOps professionals often create and manage log groups and streams using infrastructure as code tools like CloudFormation to automate deployments and maintain consistency.
Progress0 / 4 steps
1
Create the log group resource
Create a CloudFormation resource named MyAppLogGroup of type AWS::Logs::LogGroup with the property LogGroupName set to MyAppLogGroup.
AWS
Hint
Use the Resources section to define your log group resource with the exact name and type.
2
Add the log stream resource
Add a CloudFormation resource named MyAppLogStream of type AWS::Logs::LogStream with the property LogStreamName set to MyAppLogStream. Do not link it to the log group yet.
AWS
Hint
Define the log stream resource under Resources with the exact name and type.
3
Link the log stream to the log group
Add the property LogGroupName with the value MyAppLogGroup to the MyAppLogStream resource to link it to the log group.
AWS
Hint
Inside the Properties of MyAppLogStream, add LogGroupName: MyAppLogGroup.
4
Complete the CloudFormation template
Add the YAML document start marker --- at the very top of the template to complete the CloudFormation template.
AWS
Hint
The YAML document start marker is three dashes --- at the very top of the file.
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
Step 1: Understand log group role
A log group acts as a container for multiple log streams, grouping logs by application or resource.
Step 2: Differentiate from other options
Log events are stored in log streams, not directly in log groups. Access control and billing are unrelated.
Final Answer:
To organize multiple log streams into a single container -> Option A
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
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.
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.
Final Answer:
aws logs create-log-stream --log-group-name appGroup --log-stream-name appStream -> Option D
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
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.
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.
Final Answer:
Create the log stream 'myStream' inside 'myGroup' before putting events -> Option C
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
Step 1: Understand grouping and streaming roles
Log groups organize logs for management and retention. Log streams separate logs by source within groups.
Step 2: Choose best structure for microservices
Using one log group for all microservices and separate streams per microservice allows easy management and searching.
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.
Final Answer:
Create one log group for all microservices, and create separate log streams for each microservice inside it -> Option B
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 unknownstrongwhile earning +1 Grip toward your certificate.