View a markdown version of this page

Tagging your directory - Amazon Directory Service
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Tagging your directory

Tags are key-value pairs that you can assign to your Amazon Directory Service directories to help you organize and manage your resources. You can use tags to categorize directories by purpose, environment, cost allocation, and other criteria. Each tag consists of a required tag key and an optional tag value. Tag keys must be unique for each directory.

For more information about tagging strategies, see Tagging best practices.

You can run the following commands from Amazon CloudShell, which comes with the Amazon CLI, PowerShell, and AWS.Tools for PowerShell pre-installed, and credentials are automatically configured.

  1. Sign in to the Amazon Web Services Management Console.

  2. Open Amazon CloudShell. Run pwsh to use the PowerShell commands.

Add tags to your directory

You can add tags to your directory using the Amazon CLI or PowerShell:

Amazon CLI
To add tags to your directory with the Amazon CLI
  • Open the Amazon CLI. Run the following command, replacing the directory ID and tag values with your own:

    aws ds add-tags-to-resource \ --resource-id d-1234567890 \ --tags Key=MyTagName1,Value=MyTagValue1 \ Key=MyTagName2,Value=MyTagValue2

    For more information, see add-tags-to-resource.

PowerShell
To add tags to your directory with PowerShell
  • Open PowerShell. Run the following command, replacing the directory ID and tag values with your own:

    Add-DSResourceTag ` -ResourceId d-1234567890 ` -Tag @{Key="MyTagName1"; Value="MyTagValue1"}, ` @{Key="MyTagName2"; Value="MyTagValue2"}

    For more information, see Add-DSResourceTag.

List tags on your directory

You can list existing tags on your directory using the Amazon CLI or PowerShell:

Amazon CLI
To list tags on your directory with the Amazon CLI
  • Open the Amazon CLI. Run the following command, replacing the directory ID with your own:

    aws ds list-tags-for-resource \ --resource-id d-1234567890

    For more information, see list-tags-for-resource.

PowerShell
To list tags on your directory with PowerShell
  • Open PowerShell. Run the following command, replacing the directory ID with your own:

    Get-DSResourceTag ` -ResourceId d-1234567890

    For more information, see Get-DSResourceTag.

Update a tag on your directory

To update the value of an existing tag, use the same add command with the existing key name and a new value. This overwrites the previous value.

Amazon CLI
To update a tag on your directory with the Amazon CLI
  • Open the Amazon CLI. Run the following command, replacing the directory ID, tag key, and new value with your own:

    aws ds add-tags-to-resource \ --resource-id d-1234567890 \ --tags Key=MyTagName1,Value=MyNewTagValue1

    For more information, see add-tags-to-resource.

PowerShell
To update a tag on your directory with PowerShell
  • Open PowerShell. Run the following command, replacing the directory ID, tag key, and new value with your own:

    Add-DSResourceTag ` -ResourceId d-1234567890 ` -Tag @{Key="MyTagName1"; Value="MyNewTagValue1"}

    For more information, see Add-DSResourceTag.

Remove tags from your directory

You can remove tags from your directory using the Amazon CLI or PowerShell:

Amazon CLI
To remove tags from your directory with the Amazon CLI
  • Open the Amazon CLI. Run the following command, replacing the directory ID and tag key names with your own:

    aws ds remove-tags-from-resource \ --resource-id d-1234567890 \ --tag-keys MyTagName1 MyTagName2

    For more information, see remove-tags-from-resource.

PowerShell
To remove tags from your directory with PowerShell
  • Open PowerShell. Run the following command, replacing the directory ID and tag key names with your own:

    Remove-DSResourceTag ` -ResourceId d-1234567890 ` -TagKey "MyTagName1", ` "MyTagName2" ` -Force

    For more information, see Remove-DSResourceTag.