How to Group AWS Resources Based on Tags?
Use AWS Resource Groups to Logically Group AWS Resources
We can logically group AWS resources using the AWS Resource Groups service. This article will demonstrate how we can logically group EC2 instances using their tags.
I have already deployed three EC2 instances, two of them are tagged as
Env: Dev
, and other one is tagged asEnv: Test
- Let’s open Resource Groups and Tag Editor from AWS Console UI :
2. Then create a resource group:
3. Select Tag based
group type:
4. Search for the resource types ( In this case, select AWS::EC2::Instance
resource type )
5. Search for the Tags
used on the EC2 instances → Add them → Press the Preview group resources button to view matched instances.
6. Create the group with a name and description.
Similarly, we can create several resource groups based on the tags
7. View all the groups:
Use case:
After creating resource groups, the next important step is determining their use. One practical application is to utilize them as targets when managing instances through AWS Systems Manager. For example, if we need to execute a shell command on 10 instances belonging to a resource group named DevGroup, the recommended approach would be to use AWS Systems Manager's "Run Command" feature with resource groups as targets.
Following is a sample demonstration:
- Search for a command document named AWS-RunShellScript
2. Write shell commands as per requirements.
3. Choose a resource group as the target.
4. Run the command and view the progress: