Configure deletion protection for your Amazon EC2 Auto Scaling resources
Protect your Amazon EC2 Auto Scaling infrastructure from accidental deletion by configuring multiple layers of protection. Auto Scaling provides several approaches to prevent unwanted resource deletion for your Auto Scaling groups and the Amazon EC2 instances that it manages.
Contents
Configure Auto Scaling group deletion protection
Deletion protection is a resource-level setting that prevents your Amazon EC2 Auto Scaling group from accidental deletion. When enabled, deletion protection blocks the DeleteAutoScalingGroup API operation from succeeding, requiring you to first update the deletion protection setting to a less restrictive level before you can delete the Auto Scaling group.
Amazon EC2 Auto Scaling offers three levels of deletion protection:
- None (default)
-
No deletion protection is enabled, meaning your Auto Scaling group can be deleted with or without using the
ForceDeleteoption. WhenForceDeleteis used, all Amazon EC2 instances managed by your Auto Scaling group will also be forcibly terminated without executing termination lifecycle hooks. - Prevent force deletion
-
Your Auto Scaling group can't be deleted when using the
ForceDeleteoption. This configuration allows deletion of empty Auto Scaling groups (groups with no instances). This option is recommended for production workloads where you want to prevent mass instance termination but allow cleanup of empty groups. - Prevent all deletion
-
Your Auto Scaling group can't be deleted regardless of whether the
ForceDeleteoption is used. This option provides the strongest protection against accidental deletion. It requires explicitly disabling deletion protection before your Auto Scaling group can be deleted. This is recommended for mission-critical Auto Scaling groups that should rarely or never be deleted.
How deletion protection works
When you attempt the DeleteAutoScalingGroup API operation with deletion protection enabled:
-
Amazon EC2 Auto Scaling validates the deletion protection setting before processing the request.
-
If the configured deletion protection level blocks the deletion attempt, Amazon EC2 Auto Scaling returns a
ValidationError. -
Your Auto Scaling group and its Amazon EC2 instances remain unchanged.
-
You must update the deletion protection setting to a less restrictive level before you can delete your Auto Scaling group.
Deletion protection does not prevent other operations such as:
-
Updating the Auto Scaling group configuration.
-
Terminating individual instances.
-
Scaling operations (manual or automatic).
-
Suspending or resuming processes.
For more information on how to gracefully handle instance termination, see Design your applications to gracefully handle instance termination.
Configure deletion protection
You can set deletion protection when you create an Auto Scaling group or update the setting on an existing Auto Scaling group.
Control deletion permissions with IAM policies
Use AWS Identity and Access Management (IAM) policies to control which users and roles can delete Auto Scaling groups. IAM-based controls provide an additional layer of security by restricting permissions at the identity level.
IAM policies are particularly useful when you want to:
-
Allow different users different levels of access to Auto Scaling operations.
-
Prevent specific users from using the
ForceDeleteoption even if they can perform other Auto Scaling operations. -
Restrict deletion permissions to specific Auto Scaling groups.
The following policy allows deletion of an Auto Scaling group only if the group has the tag
.
environment=development
The following policy uses the autoscaling:ForceDelete condition key to control access
to the DeleteAutoScalingGroup API action. This can prevent certain users from using the
ForceDelete operation, which terminates all Amazon EC2 instances within an Auto Scaling group.
Alternatively, if you are not using condition keys to control access to Auto Scaling groups, you can specify
the ARNs of resources in the Resource element to control access instead.
The following policy gives users permissions to use the DeleteAutoScalingGroup API
action, but only for Auto Scaling groups whose name begins with .
devteam-
You can also specify multiple ARNs by enclosing them in a list. Including the UUID ensures that access is granted to the specific Auto Scaling group. The UUID for a new group is different from the UUID for a deleted group with the same name.
"Resource": [ "arn:aws:autoscaling:region:account-id:autoScalingGroup:uuid:autoScalingGroupName/devteam-1", "arn:aws:autoscaling:region:account-id:autoScalingGroup:uuid:autoScalingGroupName/devteam-2", "arn:aws:autoscaling:region:account-id:autoScalingGroup:uuid:autoScalingGroupName/devteam-3" ]
For additional examples of IAM policies for Amazon EC2 Auto Scaling, including policies that control deletion permissions, see Identity-based policy examples.