Course contentsShow
← Cloud and Infrastructure
Lesson 365 of 2,9897. Identity and Access ManagementFree lesson

Wildcards and Pattern Matching

Use wildcards in actions and resources to create flexible policies that match multiple elements.

Wildcards and Pattern Matching

What you'll learn: How to use wildcards in IAM policies to create flexible permissions that match multiple actions and resources at once.


The Power of Pattern Matching

Writing a separate policy statement for every single action or resource would be tedious and error-prone. Wildcards let you write one permission rule that covers many cases. Think of it like a search filter: instead of listing every file named "document1.txt," "document2.txt," "document3.txt," you search for "document*.txt" and catch them all.

In IAM policies, you use the asterisk (*) as a wildcard character.


Using Wildcards in Actions

You can match multiple actions from the same service:

{
  "Effect": "Allow",
  "Action": "s3:Get*",
  "Resource": "arn:aws:s3:::my-bucket/*"
}

This grants permission for all S3 actions that start with "Get"—like GetObject, GetObjectVersion, GetBucketLocation, etc.—without listing each one individually.


Using Wildcards in Resources

You can also match multiple resources:

{
  "Effect": "Allow",
  "Action": "ec2:DescribeInstances",
  "Resource": "*"
}

Here, "Resource": "*" means all resources. This is common for read-only actions that don't target specific resources.


Practical Pattern Matching

You can combine wildcards strategically:

{
  "Effect": "Allow",
  "Action": "s3:*",
  "Resource": "arn:aws:s3:::project-dev-*"
}

This allows all S3 actions on any bucket whose name starts with "project-dev-".


Key Takeaway: Wildcards (*) let you write concise, flexible IAM policies that match multiple actions or resources based on patterns, reducing repetition and simplifying permission management.