📖 Scenario: You are setting up a simple AWS environment to manage compute and storage resources. You will create a dictionary to represent AWS services and their tasks, then configure a threshold for task limits, apply logic to filter services, and finally complete the setup with a summary configuration.
🎯 Goal: Build a Python dictionary representing AWS services and their tasks, configure a task limit, filter services based on the limit, and finalize the configuration for deployment.
📋 What You'll Learn
Create a dictionary named aws_services with specific AWS services and their tasks
Add a configuration variable named task_limit with a specific integer value
Use a dictionary comprehension to create filtered_services containing only services with tasks less than or equal to task_limit
Add a final key-value pair 'deployment_ready': True to the filtered_services dictionary
💡 Why This Matters
🌍 Real World
Managing AWS services and their tasks helps in organizing cloud resources efficiently and preparing configurations for deployment.
💼 Career
Cloud engineers and DevOps professionals often create and manage service configurations to automate and optimize cloud infrastructure.
Progress0 / 4 steps
1
Create AWS services dictionary
Create a dictionary called aws_services with these exact entries: 'EC2': 5, 'S3': 3, 'Lambda': 7, 'DynamoDB': 4
AWS
Hint
Use curly braces to create a dictionary with keys as service names and values as task counts.
2
Add task limit configuration
Add a variable called task_limit and set it to the integer 5
AWS
Hint
Assign the integer 5 to the variable named task_limit.
3
Filter services by task limit
Use a dictionary comprehension to create a new dictionary called filtered_services that includes only the services from aws_services with task counts less than or equal to task_limit
AWS
Hint
Use a dictionary comprehension with for service, tasks in aws_services.items() and an if condition.
4
Complete configuration with deployment flag
Add a key-value pair 'deployment_ready': True to the filtered_services dictionary
AWS
Hint
Use the dictionary key assignment syntax to add the new key and value.
Practice
(1/5)
1. What is the main role of a service in AWS when managing your app tasks?
easy
A. To define the resources and containers for the app
B. To keep the app tasks running and replace them if they fail
C. To store data for the app
D. To monitor network traffic
Solution
Step 1: Understand what a service does
A service manages running copies of your app tasks and ensures they stay running.
Step 2: Compare with other options
Defining resources and containers is the task's role, not the service's. Storing data and monitoring traffic are unrelated.
Final Answer:
To keep the app tasks running and replace them if they fail -> Option B
Quick Check:
Service manages tasks = B [OK]
Hint: Services keep tasks running and replace failed ones [OK]
Common Mistakes:
Confusing service with task definition
Thinking service stores data
Assuming service monitors network
2. Which of the following is the correct way to define a task in AWS ECS?
easy
A. A database schema for app data
B. A YAML file listing EC2 instances
C. A JSON file specifying containers, CPU, and memory
D. A script to launch EC2 instances
Solution
Step 1: Identify task definition format
A task in AWS ECS is defined by a JSON file that specifies containers, CPU, and memory requirements.
Step 2: Eliminate incorrect options
YAML listing EC2 instances is not a task definition. Scripts to launch EC2 or database schemas are unrelated.
Final Answer:
A JSON file specifying containers, CPU, and memory -> Option C
Quick Check:
Task definition = JSON file with containers [OK]
Hint: Task definitions use JSON to specify containers and resources [OK]
Common Mistakes:
Confusing task definition with instance listing
Using scripts instead of JSON for tasks
Mixing database schemas with task definitions
3. If you create a service with a desired count of 3 tasks, but one task fails, what will AWS ECS do?
medium
A. Replace the failed task to maintain 3 running tasks
B. Stop all tasks and alert the user
C. Ignore the failure and keep 2 tasks running
D. Scale down the service to 2 tasks
Solution
Step 1: Understand service desired count behavior
The service tries to keep the number of running tasks equal to the desired count.
Step 2: What happens on task failure?
If a task fails, the service replaces it to maintain the desired count of 3 tasks.
Final Answer:
Replace the failed task to maintain 3 running tasks -> Option A
Quick Check:
Service maintains desired count = A [OK]
Hint: Service replaces failed tasks to keep desired count [OK]
Common Mistakes:
Thinking service stops all tasks on failure
Assuming service ignores failures
Believing service scales down automatically
4. You defined a task with 512 MB memory but your service fails to start tasks due to insufficient resources. What is the likely problem?
medium
A. The container image is missing
B. The task definition JSON is invalid
C. The service desired count is set to zero
D. The cluster has no available memory to run the task
Solution
Step 1: Analyze the error cause
Insufficient resources usually mean the cluster lacks enough memory to run the task.
Step 2: Check other options
Invalid JSON or zero desired count would cause different errors. Missing image causes container start failure, not resource error.
Final Answer:
The cluster has no available memory to run the task -> Option D