Sub topic 8
Assigning resources with tags or ARNs
This chapter assumes you can use the AWS CLI, understand IAM roles and policies, and have tagged AWS resources before. It also assumes you have already created a vault and a backup plan, as covered in earlier chapters.
A backup plan describes when and how to back up. It does not say what to back up. A resource assignment supplies that missing piece. Without one, a plan runs on schedule and protects nothing.
What a resource assignment is
A resource assignment (the API calls it a backup selection) connects a backup plan to a set of resources. It has three parts:
- A name that identifies the selection within the plan.
- An IAM role that AWS Backup assumes to find and back up the resources.
- A rule for choosing resources: explicit ARNs, tag conditions, or both.
A plan can have many assignments. Each assignment belongs to exactly one plan. When a rule in the plan fires, AWS Backup resolves every assignment in that plan and starts one backup job per matching resource.
Choosing by tag
Tag-based assignment is the usual choice. New resources that carry the tag are picked up automatically at the next backup, so nobody has to edit the plan.
The selection file below assigns every supported resource tagged backup=daily:
{
"SelectionName": "tagged-backup-daily",
"IAMRoleArn": "arn:aws:iam::123456789012:role/service-role/AWSBackupDefaultServiceRole",
"ListOfTags": [
{
"ConditionType": "STRINGEQUALS",
"ConditionKey": "backup",
"ConditionValue": "daily"
}
]
}Create the plan, then attach the selection using the plan ID that the first command returns:
aws backup create-backup-plan \
--backup-plan file://plan.json
aws backup create-backup-selection \
--backup-plan-id <backup-plan-id> \
--backup-selection file://selection.jsonHow tag conditions combine
Several conditions in ListOfTags are combined with a logical AND. A resource must satisfy all of them. If you want OR behavior, such as "tagged backup=daily or tagged tier=gold", create two separate assignments on the same plan.
The same tag key is matched case-sensitively, so Backup and backup are different keys. Pick one spelling and enforce it, for example with tag policies in AWS Organizations.
The ConditionType field currently accepts STRINGEQUALS. Because of that, you cannot match by prefix or wildcard in ListOfTags.
Tag selection edge cases
- The tag must be on the resource itself. A tag on a CloudFormation stack or an Auto Scaling group does not count unless it is propagated to the resource.
- Not every resource type supports tags. Resources that cannot carry tags can only be assigned by ARN.
- AWS Backup evaluates tags when the backup job is created, not when the assignment is created. A tag added a minute before the schedule fires is picked up. A tag added a minute after is not, until the next run.
Choosing by ARN
Explicit ARNs are a better fit when you want a fixed, auditable list or when a resource type cannot be tagged. You pass them in Resources:
{
"SelectionName": "named-volumes",
"IAMRoleArn": "arn:aws:iam::123456789012:role/service-role/AWSBackupDefaultServiceRole",
"Resources": [
"arn:aws:ec2:us-east-1:123456789012:volume/vol-0123456789abcdef0",
"arn:aws:rds:us-east-1:123456789012:db:orders-db"
]
}You can also use a wildcard to cover a whole family of resources, for example arn:aws:ec2:*:*:volume/* for all EBS volumes in the account. Combine it with NotResources to carve out exceptions, or with tag conditions to narrow the match.
Explicit ARNs have a cost. When someone replaces a volume or recreates a database, the ARN changes and the assignment silently stops covering the new resource. Tags survive replacement as long as the new resource is tagged.
Combining ARNs, wildcards and tags
You can mix Resources, NotResources, and Conditions in one assignment. This table summarizes how each field behaves.
| Field | Purpose | Combination rule |
|---|---|---|
| `Resources` | ARNs or wildcard ARNs to include | A resource matching any entry is a candidate |
| `NotResources` | ARNs or wildcard ARNs to exclude | Excluded even if it matches `Resources` or a tag |
| `ListOfTags` | Simple tag conditions | All conditions must match |
| `Conditions` | Advanced conditions such as `StringEquals`, `StringLike`, `StringNotEquals` | Evaluated together with the other fields |
ListOfTags is the older, simpler syntax. Conditions is the newer one and supports StringLike and StringNotLike, which allow wildcard matching on tag values. Do not use ListOfTags and Conditions together in one assignment, because the API rejects that combination.
The following selection protects all resources tagged env=prod except one database:
{
"SelectionName": "prod-except-scratch",
"IAMRoleArn": "arn:aws:iam::123456789012:role/service-role/AWSBackupDefaultServiceRole",
"Resources": ["*"],
"NotResources": [
"arn:aws:rds:us-east-1:123456789012:db:scratch-db"
],
"Conditions": {
"StringEquals": [
{
"ConditionKey": "aws:ResourceTag/env",
"ConditionValue": "prod"
}
]
}
}The service role in an assignment
The IAMRoleArn is the role AWS Backup assumes when it runs jobs for this assignment. The role needs two things:
- A trust policy that lets
backup.amazonaws.comassume it. - Permissions to back up and restore the resource types you assign.
The managed role AWSBackupDefaultServiceRole carries the AWS managed policies for backup and restore. If the role lacks permission for a resource, the job fails with an access-denied message, even though the assignment was created successfully. The API does not check permissions at creation time.
Also, you need iam:PassRole on the role to create the assignment. Without it, create-backup-selection fails.
Verifying what an assignment covers
Creating an assignment does not tell you which resources it matches. Check it from several angles.
List the assignments on a plan and read one back:
aws backup list-backup-selections \
--backup-plan-id <backup-plan-id>
aws backup get-backup-selection \
--backup-plan-id <backup-plan-id> \
--selection-id <selection-id>To see actual protected resources, use list-protected-resources. It shows resources that have at least one recovery point, with the time of the latest one:
aws backup list-protected-resourcesA resource missing from that list either has not been backed up yet or is not matched. Compare the resource's tags with the assignment, and confirm the first scheduled run has happened. For a quick test, run an on-demand backup, which a later chapter covers.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Resource never appears in protected resources | Tag key or value differs in case or spelling | Compare the tag exactly with the condition |
| Job fails with access denied | Service role lacks permission for that resource type | Attach the matching backup policy to the role |
| `create-backup-selection` is rejected | Caller lacks `iam:PassRole`, or `ListOfTags` and `Conditions` are both set | Grant PassRole, or use only one tag syntax |
| New database not backed up | Assignment used its ARN, and the database was recreated | Switch to a tag condition |
| Resource type skipped | The service is not enabled for AWS Backup in this Region | Opt in to the service under AWS Backup settings |
Exercises
Exercise
A database was recreated after a failed migration, and its new ARN differs from the old one. Backups for it stopped. The assignment lists the old ARN in Resources. What change prevents this from recurring, and what do you check afterward?
Show answer
Replace the ARN with a tag condition such as backup=daily, and make sure the recreation process applies the tag. Afterward, run aws backup list-protected-resources after the next run and confirm the new database appears with a recent recovery point.
Exercise
You want resources tagged backup=daily OR tier=gold to be protected by the same plan. How do you express it, given that conditions in one assignment are combined with AND?
Show answer
Create two assignments on the same plan: one with the condition backup=daily and one with tier=gold. A resource matching either assignment is backed up. Note that a resource matching both is still backed up once per plan run for that assignment match, so check that duplicates do not occur by reviewing the resulting jobs.