mypy-boto3-resourcegroupstaggingapi type stubs

1.42.3 · active · verified Sat Apr 11

mypy-boto3-resourcegroupstaggingapi provides type annotations for the boto3 AWS Resource Groups Tagging API service (version 1.42.3). It is automatically generated using mypy-boto3-builder 8.12.0, ensuring up-to-date static type checking for your boto3 code. As part of the wider mypy-boto3 ecosystem, it offers robust type hints for clients, paginators, and service-specific TypeDefs, with new releases frequently aligning with boto3 updates.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use the ResourceGroupsTaggingAPIClient with type annotations to retrieve AWS resources based on specific tags. It showcases initializing the client and making a basic API call with type-hinted input and output.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_resourcegroupstaggingapi import ResourceGroupsTaggingAPIClient
    from mypy_boto3_resourcegroupstaggingapi.type_defs import TagResourcesOutputTypeDef

def get_resources_with_tags(region_name: str, tags: dict[str, str]) -> TagResourcesOutputTypeDef:
    # Initialize the boto3 client with type annotation for mypy-boto3
    client: ResourceGroupsTaggingAPIClient = boto3.client(
        "resourcegroupstaggingapi",
        region_name=region_name
    )

    # Prepare tag filters for the GetResources operation
    tag_filters = [{
        "Key": k,
        "Values": [v]
    } for k, v in tags.items()]

    # Get resources with specified tags
    response = client.get_resources(
        TagFilters=tag_filters
    )

    print(f"Found {len(response.get('ResourceTagMappingList', []))} resources.")
    for resource_mapping in response.get('ResourceTagMappingList', []):
        print(f"  Resource ARN: {resource_mapping.get('ResourceARN')}")
        print(f"  Tags: {resource_mapping.get('Tags')}")
    return response

# Example usage:
if __name__ == "__main__":
    # Replace 'us-east-1' with your desired AWS region
    # Make sure your AWS credentials are configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_NAME env vars or ~/.aws/credentials)
    try:
        result = get_resources_with_tags(
            region_name="us-east-1",
            tags={
                "Environment": "Production",
                "Project": "MyProject"
            }
        )
    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →