|
| 1 | +--- |
| 2 | +title: "Resource Groups Tagging API" |
| 3 | +tags: ["Base"] |
| 4 | +description: Get started with Resource Groups Tagging API on LocalStack |
| 5 | +--- |
| 6 | + |
| 7 | +import FeatureCoverage from "../../../../components/feature-coverage/FeatureCoverage"; |
| 8 | + |
| 9 | +## Introduction |
| 10 | + |
| 11 | +Resource Groups Tagging API helps you centrally manage tags across AWS resources. |
| 12 | +You can apply and remove tags for multiple resources at once, and query resources by tag keys and values. |
| 13 | +You can also query tagged resources by AWS service, by resource type within a service, or directly by specific resource ARNs. |
| 14 | + |
| 15 | +LocalStack allows you to use the Resource Groups Tagging API in your local environment to test tagging workflows end-to-end. |
| 16 | +The supported APIs are available on our [API Coverage section](#api-coverage), which provides information on the extent of Resource Groups Tagging API's integration with LocalStack. |
| 17 | + |
| 18 | +## Getting started |
| 19 | + |
| 20 | +This guide is designed for users new to Resource Groups Tagging API and assumes basic knowledge of the AWS CLI and our [`awslocal`](https://github.com/localstack/awscli-local) wrapper script. |
| 21 | + |
| 22 | +Start your LocalStack container using your preferred method. |
| 23 | +We will demonstrate how to create resources, tag them, and query them using the Resource Groups Tagging API. |
| 24 | + |
| 25 | +### Create resources to tag |
| 26 | + |
| 27 | +Create an S3 bucket and an SQS queue: |
| 28 | + |
| 29 | +```bash |
| 30 | +BUCKET_NAME="rg-tagging-bucket" |
| 31 | +QUEUE_NAME="rg-tagging-queue" |
| 32 | + |
| 33 | +awslocal s3api create-bucket --bucket "$BUCKET_NAME" |
| 34 | +QUEUE_URL=$(awslocal sqs create-queue --queue-name "$QUEUE_NAME" | jq -r '.QueueUrl') |
| 35 | +``` |
| 36 | + |
| 37 | +Retrieve the resource ARNs: |
| 38 | + |
| 39 | +```bash |
| 40 | +BUCKET_ARN="arn:aws:s3:::$BUCKET_NAME" |
| 41 | +QUEUE_ARN=$(awslocal sqs get-queue-attributes \ |
| 42 | + --queue-url "$QUEUE_URL" \ |
| 43 | + --attribute-names QueueArn | jq -r '.Attributes.QueueArn') |
| 44 | +``` |
| 45 | + |
| 46 | +### Tag multiple resources |
| 47 | + |
| 48 | +Use the [`TagResources`](https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_TagResources.html) API to apply tags: |
| 49 | + |
| 50 | +```bash |
| 51 | +awslocal resourcegroupstaggingapi tag-resources \ |
| 52 | + --resource-arn-list "$BUCKET_ARN" "$QUEUE_ARN" \ |
| 53 | + --tags '{"Environment":"dev","Team":"platform"}' |
| 54 | +``` |
| 55 | + |
| 56 | +### Query resources by tags |
| 57 | + |
| 58 | +Use the [`GetResources`](https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_GetResources.html) API to list resources with a specific tag: |
| 59 | + |
| 60 | +```bash |
| 61 | +awslocal resourcegroupstaggingapi get-resources \ |
| 62 | + --tag-filters Key=Environment,Values=dev |
| 63 | +``` |
| 64 | + |
| 65 | +You can also inspect available keys and values: |
| 66 | + |
| 67 | +```bash |
| 68 | +awslocal resourcegroupstaggingapi get-tag-keys |
| 69 | +awslocal resourcegroupstaggingapi get-tag-values --key Environment |
| 70 | +``` |
| 71 | + |
| 72 | +### Remove tags from resources |
| 73 | + |
| 74 | +Use the [`UntagResources`](https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/API_UntagResources.html) API to remove one or more tag keys: |
| 75 | + |
| 76 | +```bash |
| 77 | +awslocal resourcegroupstaggingapi untag-resources \ |
| 78 | + --resource-arn-list "$BUCKET_ARN" "$QUEUE_ARN" \ |
| 79 | + --tag-keys Team |
| 80 | +``` |
| 81 | + |
| 82 | +## Supported services |
| 83 | + |
| 84 | +LocalStack's Resource Groups Tagging API supports tagging for the following services: |
| 85 | + |
| 86 | +- [AWS Key Management Service (KMS)](/aws/services/kms/) |
| 87 | +- [Amazon S3](/aws/services/s3/) |
| 88 | +- [AWS Lambda](/aws/services/lambda/) |
| 89 | +- [Amazon Route 53](/aws/services/route53/) |
| 90 | +- [Amazon SNS](/aws/services/sns/) |
| 91 | +- [Amazon SQS](/aws/services/sqs/) |
| 92 | +- [Amazon OpenSearch Service](/aws/services/opensearch/) |
| 93 | +- [AWS Elastic Beanstalk](/aws/services/elasticbeanstalk/) |
| 94 | +- [Amazon EC2](/aws/services/ec2/) |
| 95 | + |
| 96 | +## API Coverage |
| 97 | + |
| 98 | +<FeatureCoverage service="resourcegroupstaggingapi" client:load /> |
0 commit comments