Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
S3 Lifecycle Rules Setup
📖 Scenario: You manage a cloud storage bucket that holds many files. To save money and keep the storage tidy, you want to automatically move files to cheaper storage after some days and delete old files after a longer time.
🎯 Goal: Create an AWS S3 bucket lifecycle configuration that moves files to the STANDARD_IA storage class after 30 days and deletes files after 365 days.
📋 What You'll Learn
Create a lifecycle rule named exactly ArchiveAndExpireRule
Set the rule to apply to all objects in the bucket
Transition objects to STANDARD_IA storage class after 30 days
Expire (delete) objects after 365 days
Enable the lifecycle rule
💡 Why This Matters
🌍 Real World
S3 lifecycle rules help manage storage costs by automatically moving or deleting files based on age.
💼 Career
Cloud engineers and DevOps professionals use lifecycle rules to optimize storage and reduce expenses.
Progress0 / 4 steps
1
Create the basic lifecycle configuration structure
Create a variable called lifecycle_configuration and assign it a dictionary with a key Rules that holds an empty list.
AWS
Hint
This is the container for all lifecycle rules. Start with an empty list for rules.
2
Add the lifecycle rule configuration dictionary
Add a dictionary to the Rules list inside lifecycle_configuration with the key ID set to "ArchiveAndExpireRule", and Status set to "Enabled".
AWS
Hint
The rule needs a name and must be enabled to work.
3
Add transition and expiration actions to the rule
Inside the rule dictionary in lifecycle_configuration["Rules"], add a Filter key with an empty dictionary, a Transitions key with a list containing a dictionary that sets Days to 30 and StorageClass to "STANDARD_IA", and an Expiration key with a dictionary setting Days to 365.
AWS
Hint
The filter applies to all objects. Transition moves files after 30 days. Expiration deletes after 365 days.
4
Complete the lifecycle configuration for deployment
Ensure the lifecycle_configuration dictionary is fully defined with the Rules list containing the rule dictionary with keys ID, Status, Filter, Transitions, and Expiration as specified. This configuration is ready to be used with AWS SDK or CLI to set the bucket lifecycle.
AWS
Hint
This is the final lifecycle configuration dictionary ready for deployment.
Practice
(1/5)
1. What is the main purpose of an S3 lifecycle rule?
easy
A. To automatically move or delete files based on time to save costs
B. To manually upload files to S3 buckets
C. To create backups of files in S3
D. To encrypt files stored in S3
Solution
Step 1: Understand lifecycle rule purpose
S3 lifecycle rules automate management of files by moving or deleting them after a set time.
Step 2: Compare options with lifecycle rule function
Only To automatically move or delete files based on time to save costs describes automatic moving or deleting files to save costs, which matches lifecycle rules.
Final Answer:
To automatically move or delete files based on time to save costs -> Option A
Quick Check:
Lifecycle rules automate file management = C [OK]
Hint: Lifecycle rules automate file moves or deletes by time [OK]
Common Mistakes:
Confusing lifecycle rules with manual upload
Thinking lifecycle rules create backups
Assuming lifecycle rules encrypt files
2. Which of the following is the correct JSON snippet to define a lifecycle rule that deletes objects after 30 days?
easy
A. {"Rules": [{"Status": "Disabled", "Expiration": {"Days": 30}}]}
B. {"Rules": [{"Status": "Enabled", "Transition": {"Days": 30}}]}
C. {"Rules": [{"Status": "Enabled", "Expiration": {"Days": 30}}]}
D. {"Rules": [{"Status": "Enabled", "Expiration": {"Date": 30}}]}
Solution
Step 1: Identify correct lifecycle rule syntax for expiration
The expiration action uses "Expiration" with "Days" key and rule must be "Enabled".
Step 2: Check each option for correct keys and values
{"Rules": [{"Status": "Enabled", "Expiration": {"Days": 30}}]} uses "Expiration" with "Days":30 and "Status":"Enabled" which is correct. {"Rules": [{"Status": "Enabled", "Transition": {"Days": 30}}]} uses "Transition" which is for storage class change, not deletion. {"Rules": [{"Status": "Disabled", "Expiration": {"Days": 30}}]} disables the rule. {"Rules": [{"Status": "Enabled", "Expiration": {"Date": 30}}]} uses "Date" instead of "Days" which is invalid.
Final Answer:
{"Rules": [{"Status": "Enabled", "Expiration": {"Days": 30}}]} -> Option C
Quick Check:
Expiration with Days and Enabled status = A [OK]
Hint: Expiration uses "Days" and rule must be enabled [OK]
Common Mistakes:
Using Transition instead of Expiration for deletion
Setting rule status to Disabled
Using Date instead of Days for expiration
3. Given this lifecycle rule snippet, what happens to objects after 60 days?
A. Objects in the 'logs/' folder are moved to Glacier storage after 60 days
B. Objects in the 'logs/' folder are deleted after 60 days
C. All objects in the bucket are moved to Glacier after 60 days
D. Objects in the 'logs/' folder are archived immediately
Solution
Step 1: Understand the Transition action with Prefix
The rule targets objects with prefix "logs/" and transitions them to Glacier after 60 days.
Step 2: Analyze options against rule behavior
Objects in the 'logs/' folder are moved to Glacier storage after 60 days correctly states objects in 'logs/' move to Glacier after 60 days. Objects in the 'logs/' folder are deleted after 60 days incorrectly says deletion. All objects in the bucket are moved to Glacier after 60 days incorrectly applies to all objects, not just prefix. Objects in the 'logs/' folder are archived immediately says immediate archive which is wrong.
Final Answer:
Objects in the 'logs/' folder are moved to Glacier storage after 60 days -> Option A
Quick Check:
Transition with prefix moves files after days = A [OK]
Hint: Transition moves files after days, prefix limits target [OK]
Common Mistakes:
Confusing Transition with Expiration (deletion)
Ignoring the prefix filter
Assuming all bucket objects are affected
4. You wrote this lifecycle rule but it does not delete files after 90 days:
C. Expiration action cannot be used without Transition
D. Rule is missing a filter or prefix to target objects
Solution
Step 1: Recall S3 lifecycle rule required fields
Every lifecycle rule requires a unique "ID" field only if using AWS CLI or SDKs; however, in JSON configuration for S3 console, "ID" is optional. Filter or prefix is required to target objects; otherwise, the rule applies to all objects.
Step 2: Analyze given rule
The rule lacks a filter or prefix, so it applies to all objects. If files are not deleting, likely the rule is not targeting the intended objects. Missing "ID" is not always mandatory (A wrong). Status "Enabled" is correct (B wrong). Expiration works standalone (C wrong). Filter or prefix is needed to target specific objects (D correct).
Final Answer:
Rule is missing a filter or prefix to target objects -> Option D
Quick Check:
Missing filter or prefix means rule may not target intended objects = D [OK]
Hint: Filter or prefix is needed to target objects for deletion [OK]
Common Mistakes:
Believing filter or prefix is optional (A)
Thinking Expiration requires Transition (C)
Status should be Disabled to activate (B)
5. You want to save costs by moving files older than 30 days to STANDARD_IA storage and delete files older than 365 days, but only for files in the archive/ folder. Which lifecycle rule setup achieves this?
Step 1: Identify correct keys for multiple transitions and expiration
Multiple transitions require "Transitions" array. Expiration is separate. Filter with Prefix targets 'archive/'.
Step 2: Check each option for correct days and storage class order
{
"Rules": [{
"Status": "Enabled",
"Prefix": "archive/",
"Transition": {"Days": 365, "StorageClass": "STANDARD_IA"},
"Expiration": {"Days": 30}
}]
} reverses days and expiration. {
"Rules": [{
"Status": "Enabled",
"Filter": {"Prefix": "archive/"},
"Transitions": [{"Days": 30, "StorageClass": "STANDARD_IA"}],
"Expiration": {"Days": 365}
}]
} correctly uses "Transitions" array with 30 days to STANDARD_IA and expiration at 365 days, with filter prefix. {
"Rules": [{
"Status": "Enabled",
"Filter": {"Prefix": "archive/"},
"Transition": {"Days": 365, "StorageClass": "STANDARD_IA"},
"Expiration": {"Days": 30}
}]
} uses singular "Transition" but reverses days (365 to IA, expire 30). {
"Rules": [{
"Status": "Enabled",
"Filter": {"Prefix": "archive/"},
"Transitions": [{"Days": 365, "StorageClass": "STANDARD_IA"}],
"Expiration": {"Days": 30}
}]
} reverses days and expiration.
Step 3: Choose best practice with multiple transitions
{
"Rules": [{
"Status": "Enabled",
"Filter": {"Prefix": "archive/"},
"Transitions": [{"Days": 30, "StorageClass": "STANDARD_IA"}],
"Expiration": {"Days": 365}
}]
} uses "Transitions" array which is best practice for multiple transitions, even if only one here, and matches requirements.
Final Answer:
Rule with Filter prefix 'archive/', Transitions at 30 days to STANDARD_IA, Expiration at 365 days -> Option B
Quick Check:
Multiple transitions use "Transitions" array, filter prefix set = B [OK]
Hint: Use "Transitions" array for multiple moves, filter prefix to target folder [OK]
Common Mistakes:
Confusing Transition singular vs Transitions array