Files
floci/docs/services/resource-groups-tagging.md
T
Mario Toffia 560de5c13f fix(tagging): find resources by the tags their own service holds (#4563)
* fix(tagging): list resources by the tags their own service holds

GetResources, GetTagKeys and GetTagValues merge the tagging store with every
ResourceProvider, so SQS, Lambda and Logs tags are discoverable. Resource type
filters now parse colon and leading-slash ARNs (function:f, log-group:x, /apikeys/k),
and TagResources/UntagResources write through to the owning TagHandler.

* fix(apigateway): expose tagged resources and API key tags to the tagging API

ApiGatewayService is a ResourceProvider for REST APIs, stages, API keys, usage plans and
domain names, and ApiGatewayTagHandler serves /apikeys/<id> ARNs, so GetResources finds
API Gateway resources by tag and tagging-API writes land on the API key itself.

* fix(cloudformation): forward AWS::Lambda::Function Tags

CreateFunction now receives the template Tags; an in-place UpdateStack untags dropped keys and retags the desired set, mirroring SqsCfnProvisioner.

* fix(tagging): scope global-ARN resources by region and clamp stale page tokens

Provider resources with an empty ARN region use their own region, stale page tokens
past the end return an empty page, and provider tags are copied inside the skip guard.

* test(compat): discover SQS, Lambda, Logs and API Gateway resources by tag

* docs(tagging): describe owning-service discovery

* fix(tagging): forward tags only for resources the owning service lists

* fix(apigateway): report the calling account and tag usage plans

* docs(cloudformation): note Lambda tag reconciliation on update

* fix(tagging): match declared resource types and scope owner writes to the request

API Gateway API key and usage plan ARNs must now name the key or plan at the
start of the resource part, so a nested /apikeys/ segment no longer tags the key.

* fix(tagging): match AWS type filters, regions and failure codes

Compared against a live AWS account: type filters, IAM listing, cross-region
TagResources and FailedResourcesMap entries now answer as AWS does.

* fix(cloudformation): keep Lambda tags added outside the template

* fix(tagging): route TagResources to V1 tag handlers too

* fix(apigateway): reject sub-resource ARNs when tagging a REST API

* fix(tagging): write tagging API tags through to SQS, Lambda and Logs

TagResources and UntagResources now reach the queue, function or log group's own tags through TagHandler beans qualified @TaggingApiOnly, so ListQueueTags, Lambda ListTags and Logs ListTagsForResource show them. The qualifier keeps these handlers off the /tags/{arn} and /v1/tags/{arn} paths, since each service defines tags in its own protocol.

* fix(cloudformation): forward SSM parameter tags

AWS::SSM::Parameter now applies its Tags after the overwriting put. On UpdateStack only the keys the previous template set and the new one drops are removed, tracked in the internal FlociSsmTemplateTagKeys attribute, so tags added outside the template are kept.

* fix(tagging): hide tagging-store copies of global resources

GetResources no longer lists an IAM role or user tagged through TagResources, since AWS never lists global resources.

* fix(tagging): reject every wildcard log group ARN

TagResources and UntagResources now send a log group ARN ending in :* to CloudWatch Logs even when the group does not exist, so it is rejected as in AWS instead of stored.

* fix(tagging): clear store tags on every untag

UntagResources now removes the keys from the tagging store for every ARN, even one the owning service rejects, so a copy stored earlier can always be cleared.

* fix(cloudformation): tag an adopted Lambda function

When CreateFunction conflicts and the provisioner adopts the existing function, the template's tags are now applied to it.

* fix(apigateway): tag only exact domain and stage ARNs

A domain or stage segment nested elsewhere in an API Gateway ARN, such as /restapis/<id>/domainnames/<d>, is now rejected instead of tagging that domain or stage.

* fix(cloudformation): leave an adopted Lambda function's tags alone

Adoption uses the existing function as it is, as before, so a function outside the stack keeps its tags.

* fix(cloudformation): record no template tag keys for an adopted Lambda function

An adopted function keeps its own tags, so a later update adds the template's tags without removing any it never set.

* fix(tagging): never list IAM ARNs from the tagging store

A role tagged through TagResources stays hidden after DeleteRole, as AWS never lists IAM resources.

* fix(tagging): fail a write when an owning service cannot be read

A provider that fails while routing TagResources or UntagResources now returns InternalServiceException instead of writing the tagging store and reporting success.

* fix(tagging): fail only unresolved ARNs when a provider cannot be read

A provider failure no longer fails the whole TagResources or UntagResources call; only ARNs whose owner could not be resolved are reported in FailedResourcesMap.

* fix(tagging): report another account's ARN instead of storing it

TagResources and UntagResources report an ARN from another account in FailedResourcesMap with AccessDeniedException, as AWS reports it per ARN, and never write it to the tagging store.

* fix(tagging): keep stored tags for an ARN an untag could not resolve

UntagResources leaves the tagging store unchanged for an ARN it reports as unresolved or from another account; an ARN its owner rejected is still cleared.

* fix(tagging): fail an unresolved ARN only when its own service cannot be read

A provider failure now only affects unlisted ARNs of the services that provider declares.

* fix(tagging): copy stored tags under the writers' lock

GetResources, GetTagKeys and GetTagValues no longer race a concurrent TagResources on a stored mapping.

* fix(apigateway): reject reserved tags when tagging a usage plan

TagResources on a usage plan now refuses floci:override-id as the other API Gateway tag paths do, instead of dropping it and reporting success.

* fix(apigateway): reject tag ARNs with an account or another region

The /tags path now answers an ARN with an account segment with BadRequestException and one naming another region with NotFoundException, as AWS does, instead of resolving the id in the caller's region.

* fix(ssm,lambda): reject tag keys outside the AWS pattern

AddTagsToResource, PutParameter, TagResource and CreateFunction now reject a tag key outside the AWS pattern or 1 to 128 characters with ValidationException, as AWS does, which also keeps the CloudFormation managed-key attributes lossless.

* fix(ssm,lambda): validate CloudFormation tag keys before changing the resource

* docs(tagging): say every handled ARN ending in :* reaches its service

* fix(tagging): read a negative pagination token as the first page
2026-09-30 06:10:27 -04:00

8.1 KiB

Resource Groups Tagging API

Protocol: JSON 1.1 Header: X-Amz-Target: ResourceGroupsTaggingAPI_20170126.<Action> Endpoint prefix: tagging

Floci emulates the AWS Resource Groups Tagging API for local tests that need centralized tag discovery across AWS-shaped ARNs. GetResources, GetTagKeys and GetTagValues list both the tags written through this API and the tags each resource's own service holds, so a queue created with CreateQueue tags is found without a separate TagResources call. Any other ARN is accepted as well, and its tags are kept in the tagging store.

Supported Operations

Operation Notes
TagResources Adds or updates tags for one or more resource ARNs
UntagResources Removes tag keys from one or more resource ARNs
GetResources Lists tagged resources, with ARN, tag, resource type, and pagination filters
GetTagKeys Lists distinct tag keys for the current region
GetTagValues Lists distinct values for a requested tag key in the current region

TagResources and UntagResources return an empty FailedResourcesMap on success. An ARN the owning service rejected is listed there with that service's own StatusCode, ErrorCode and ErrorMessage, such as 400 BadRequestException for a reserved floci: key on an API key, and the call still returns HTTP 200. An ARN that names a region other than the request's fails the whole call with HTTP 400 InvalidParameterException, Region in the ARN <arn> does not match with the region in which TagResources API is invoked (or UntagResources), and nothing is tagged or untagged. GetResources, GetTagKeys, and GetTagValues support pagination tokens for multi-page responses; a token past the last result returns an empty page.

Resource discovery

Reads merge two sources for the request's region and account:

  • The owning service's tags, for every service that Resource Explorer 2 indexes, including SQS, Lambda, CloudWatch Logs, S3 and API Gateway (REST APIs, stages, API keys, usage plans and custom domain names). Only resources that carry at least one tag are listed.
  • The tagging store, which holds tags written through TagResources that were not forwarded to an owning service, and the copies EventBridge and Glue keep there.

When both hold the same ARN, the result is one mapping, and for the same key the owning service's value wins. CloudWatch Logs log group ARNs are returned without the trailing :*.

TagResources forwards the tags to the owning service only when that service registers a tag handler, such as API Gateway, MSK, SQS, Lambda or CloudWatch Logs, and currently lists the exact ARN as one of its resources visible to the request's region and account, by the same rule reads use. The tags then live only in the owning service, so GetApiKey, ListQueueTags, Lambda ListTags and CloudWatch Logs ListTagsForResource show a tag set through TagResources, and nothing is written to the tagging store. When the owning service rejects the tags, for example a reserved floci: key on an API key or a log group ARN with the trailing :*, the ARN appears in FailedResourcesMap with that service's error and no tags are stored for it. A log group ARN with the trailing :* is rejected this way whether or not the group exists, as in AWS, and so is any other ARN ending in :* whose service registers a tag handler, such as an SQS queue ARN. Every other ARN, including one the owning service does not list such as an API Gateway deployment ARN, goes to the tagging store and the owning service is not called. UntagResources routes the same way, and also removes the keys from the tagging store for every ARN, including one the owning service rejects but not one reported as unresolved or from another account, so a copy stored earlier can always be cleared. When the service owning an ARN cannot be read while routing and no service lists the ARN, it is reported in FailedResourcesMap with InternalServiceException (status 500) and left unchanged, while ARNs a service lists, and ARNs of services that were read, still go through. An ARN from another account is reported in FailedResourcesMap with AccessDeniedException (status 403) and nothing is tagged; AWS also reports it per ARN, but with the owning service's own error, such as InvalidAddress for SQS or ValidationException for CloudWatch Logs.

Filtering

GetResources supports the common Resource Groups Tagging filters:

Filter Behavior
ResourceARNList Restricts results to the requested ARNs
TagFilters Matches resources that have each requested key; values are optional
ResourceTypeFilters Matches service or service:resourceType, such as lambda, lambda:function or ec2:instance
ResourcesPerPage + PaginationToken Pages through matching resource mappings

The resource type in service:resourceType matches the ARN's type, which is the ARN resource part with one leading / dropped, cut at the first / or :, or the type the owning service declares for the resource. So lambda:function, logs:log-group, ec2:instance, apigateway:apikeys and apigateway:restapis/stages all match. SQS queue ARNs have no type segment, so sqs:queue matches through the type SQS declares for its queues. As in AWS, apigateway:restapis lists REST APIs together with their stages, and a filter type with a leading /, such as apigateway:/apikeys, matches nothing.

A resource is visible in the region its ARN names. When the ARN has no region, such as an S3 bucket ARN, the owning service's region for the resource decides, also for tags the tagging store holds for that ARN, so an eu-west-1 bucket tagged through TagResources is not listed from us-east-1. A region-less ARN known only to the tagging store is visible in every region. As in AWS, a resource the owning service reports without a region, or in the region global as IAM does for users and roles, is never listed, and TagResources does not forward to its owning service; an IAM ARN is never listed at all, even one only the tagging store holds, for example after the role is deleted. Every store is per account, so results are scoped to the calling account. An ARN with an empty account segment, such as an API Gateway ARN, only leaves the account out of the ARN; the resource is still listed for the account that owns it.

Configuration

Variable Default Description
FLOCI_SERVICES_TAGGING_ENABLED true Enable or disable the Resource Groups Tagging API service
FLOCI_STORAGE_SERVICES_TAGGING_MODE (global storage mode) Override the storage mode for the tagging store
FLOCI_STORAGE_SERVICES_TAGGING_FLUSH_INTERVAL_MS 5000 Flush interval for the tagging store in hybrid mode

Examples

export AWS_ENDPOINT_URL=http://localhost:4566
export AWS_DEFAULT_REGION=us-east-1
export AWS_ACCESS_KEY_ID=test
export AWS_SECRET_ACCESS_KEY=test

aws resourcegroupstaggingapi tag-resources \
  --resource-arn-list arn:aws:ec2:us-east-1:000000000000:instance/i-abc123 \
  --tags Environment=dev Team=platform

aws resourcegroupstaggingapi get-resources \
  --tag-filters Key=Environment,Values=dev

aws resourcegroupstaggingapi get-tag-keys

aws resourcegroupstaggingapi get-tag-values --key Environment

aws resourcegroupstaggingapi untag-resources \
  --resource-arn-list arn:aws:ec2:us-east-1:000000000000:instance/i-abc123 \
  --tag-keys Team
import boto3

tagging = boto3.client(
    "resourcegroupstaggingapi",
    endpoint_url="http://localhost:4566",
    region_name="us-east-1",
)

arn = "arn:aws:lambda:us-east-1:000000000000:function:my-func"

tagging.tag_resources(
    ResourceARNList=[arn],
    Tags={"Environment": "dev", "Team": "platform"},
)

resources = tagging.get_resources(
    TagFilters=[{"Key": "Environment", "Values": ["dev"]}],
)
print(resources["ResourceTagMappingList"])

Out of Scope

  • Validation that a TagResources ARN names an existing resource: an ARN that no emulated service lists is accepted and kept in the tagging store.
  • AWS Organizations tag policy enforcement.