To create a retention rule
Use the create-rule
Amazon CLI command. For --retention-period
, specify the number of days to retain deleted snapshots
in the Recycle Bin. For --resource-type
, specify EBS_SNAPSHOT
for snapshots or
EC2_IMAGE
for AMIs. To create a tag-level retention rule, for --resource-tags
,
specify the tags to use to identify the snapshots that are to be retained. To create a Region-level
retention rule, omit --resource-tags
, and optionally specify --exclude-resource-tags
,
to exclude resources that have specific tags. To lock a Region-level retention
rule, include --lock-configuration
, and specify the unlock delay period in days.
aws rbin create-rule \
--retention-period RetentionPeriodValue=number_of_days
,RetentionPeriodUnit=DAYS \
--resource-type EBS_SNAPSHOT|EC2_IMAGE
\
--description "rule_description
" \
--lock-configuration 'UnlockDelay={UnlockDelayUnit=DAYS,UnlockDelayValue=unlock_delay_in_days
}' \
--resource-tags ResourceTagKey=tag_key
,ResourceTagValue=tag_value
\
--exclude-resource-tags ResourceTagKey=tag_key
,ResourceTagValue=tag_value
Example 1
The following example command creates an unlocked
Region-level retention rule that retains all deleted
snapshots for a period of 7
days.
aws rbin create-rule \
--retention-period RetentionPeriodValue=7,RetentionPeriodUnit=DAYS \
--resource-type EBS_SNAPSHOT \
--description "Match all snapshots"
Example 2
The following example command creates a tag-level rule that retains deleted snapshots
that are tagged with purpose=production
for a period of
7
days.
aws rbin create-rule \
--retention-period RetentionPeriodValue=7,RetentionPeriodUnit=DAYS \
--resource-type EBS_SNAPSHOT \
--description "Match snapshots with a specific tag" \
--resource-tags ResourceTagKey=purpose,ResourceTagValue=production
Example 3
The following example command creates a locked
Region-level retention rule that retains all deleted snapshots for a
period of 7
days. The
retention rule is locked with an unlock delay period of 7
days.
aws rbin create-rule \
--retention-period RetentionPeriodValue=7,RetentionPeriodUnit=DAYS \
--resource-type EBS_SNAPSHOT \
--description "Match all snapshots" \
--lock-configuration 'UnlockDelay={UnlockDelayUnit=DAYS,UnlockDelayValue=7}'
Example 4
The following example command creates an unlocked
Region-level retention rule that retains all deleted snapshots, except
snapshots that are tagged with purpose:testing
, for a period of
7
days.
aws rbin create-rule \
--retention-period RetentionPeriodValue=7,RetentionPeriodUnit=DAYS \
--resource-type EBS_SNAPSHOT \
--description "Match only production snapshots" \
--exclude-resource-tags ResourceTagKey=purpose,ResourceTagValue=testing