0
0
AWScloud~15 mins

Instance states (running, stopped, terminated) in AWS - Mini Project: Build & Apply

Choose your learning style9 modes available
Instance states (running, stopped, terminated)
📖 Scenario: You are managing cloud servers called instances. Each instance can be in one of three states: running, stopped, or terminated. You want to keep track of these states to manage your cloud resources efficiently.
🎯 Goal: Create a simple data structure to hold instance IDs and their states. Then, add a configuration variable to select which state to filter. Next, write code to find all instances in that selected state. Finally, complete the setup by preparing the filtered list for further management.
📋 What You'll Learn
Create a dictionary named instances with exact instance IDs as keys and their states as values.
Add a variable named selected_state with the value 'running'.
Use a dictionary comprehension named filtered_instances to select instances matching selected_state.
Add a final line to create a list named instance_ids containing only the keys from filtered_instances.
💡 Why This Matters
🌍 Real World
Cloud administrators often need to track and manage instances based on their states to optimize costs and performance.
💼 Career
Understanding instance states and filtering them is a fundamental skill for cloud engineers and DevOps professionals managing AWS resources.
Progress0 / 4 steps
1
Create the initial instance states dictionary
Create a dictionary called instances with these exact entries: 'i-101': 'running', 'i-102': 'stopped', 'i-103': 'terminated', 'i-104': 'running', 'i-105': 'stopped'.
AWS
Need a hint?

Use curly braces to create a dictionary. Each key is an instance ID string, and each value is its state string.

2
Add the selected state variable
Add a variable called selected_state and set it to the string 'running'.
AWS
Need a hint?

Just assign the string 'running' to the variable selected_state.

3
Filter instances by selected state
Use a dictionary comprehension named filtered_instances to select only those instances from instances where the state equals selected_state.
AWS
Need a hint?

Use a dictionary comprehension with for instance_id, state in instances.items() and filter by state == selected_state.

4
Create list of filtered instance IDs
Add a line to create a list called instance_ids that contains only the keys from filtered_instances.
AWS
Need a hint?

Use list(filtered_instances.keys()) to get the list of instance IDs.