EC2 / Client / describe_tags

describe_tags#

EC2.Client.describe_tags(**kwargs)#

Describes the specified tags for your EC2 resources.

For more information about tags, see Tag your Amazon EC2 resources in the Amazon Elastic Compute Cloud User Guide.

Warning

We strongly recommend using only paginated requests. Unpaginated requests are susceptible to throttling and timeouts.

Note

The order of the elements in the response, including those within nested structures, might vary. Applications should not assume the elements appear in a particular order.

See also: AWS API Documentation

Request Syntax

response = client.describe_tags(
    DryRun=True|False,
    Filters=[
        {
            'Name': 'string',
            'Values': [
                'string',
            ]
        },
    ],
    MaxResults=123,
    NextToken='string'
)
Parameters:
  • DryRun (boolean) – Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • Filters (list) –

    The filters.

    • key - The tag key.

    • resource-id - The ID of the resource.

    • resource-type - The resource type. For a list of possible values, see TagSpecification.

    • tag:<key> - The key/value combination of the tag. For example, specify “tag:Owner” for the filter name and “TeamA” for the filter value to find resources with the tag “Owner=TeamA”.

    • value - The tag value.

    • (dict) –

      A filter name and value pair that is used to return a more specific list of results from a describe operation. Filters can be used to match a set of resources by specific criteria, such as tags, attributes, or IDs.

      If you specify multiple filters, the filters are joined with an AND, and the request returns only results that match all of the specified filters.

      • Name (string) –

        The name of the filter. Filter names are case-sensitive.

      • Values (list) –

        The filter values. Filter values are case-sensitive. If you specify multiple values for a filter, the values are joined with an OR, and the request returns all results that match any of the specified values.

        • (string) –

  • MaxResults (integer) – The maximum number of items to return for this request. This value can be between 5 and 1000. To get the next page of items, make another request with the token returned in the output. For more information, see Pagination.

  • NextToken (string) – The token returned from a previous paginated request. Pagination continues from the end of the items returned by the previous request.

Return type:

dict

Returns:

Response Syntax

{
    'NextToken': 'string',
    'Tags': [
        {
            'Key': 'string',
            'ResourceId': 'string',
            'ResourceType': 'capacity-reservation'|'client-vpn-endpoint'|'customer-gateway'|'carrier-gateway'|'coip-pool'|'dedicated-host'|'dhcp-options'|'egress-only-internet-gateway'|'elastic-ip'|'elastic-gpu'|'export-image-task'|'export-instance-task'|'fleet'|'fpga-image'|'host-reservation'|'image'|'import-image-task'|'import-snapshot-task'|'instance'|'instance-event-window'|'internet-gateway'|'ipam'|'ipam-pool'|'ipam-scope'|'ipv4pool-ec2'|'ipv6pool-ec2'|'key-pair'|'launch-template'|'local-gateway'|'local-gateway-route-table'|'local-gateway-virtual-interface'|'local-gateway-virtual-interface-group'|'local-gateway-route-table-vpc-association'|'local-gateway-route-table-virtual-interface-group-association'|'natgateway'|'network-acl'|'network-interface'|'network-insights-analysis'|'network-insights-path'|'network-insights-access-scope'|'network-insights-access-scope-analysis'|'placement-group'|'prefix-list'|'replace-root-volume-task'|'reserved-instances'|'route-table'|'security-group'|'security-group-rule'|'snapshot'|'spot-fleet-request'|'spot-instances-request'|'subnet'|'subnet-cidr-reservation'|'traffic-mirror-filter'|'traffic-mirror-session'|'traffic-mirror-target'|'transit-gateway'|'transit-gateway-attachment'|'transit-gateway-connect-peer'|'transit-gateway-multicast-domain'|'transit-gateway-policy-table'|'transit-gateway-route-table'|'transit-gateway-route-table-announcement'|'volume'|'vpc'|'vpc-endpoint'|'vpc-endpoint-connection'|'vpc-endpoint-service'|'vpc-endpoint-service-permission'|'vpc-peering-connection'|'vpn-connection'|'vpn-gateway'|'vpc-flow-log'|'capacity-reservation-fleet'|'traffic-mirror-filter-rule'|'vpc-endpoint-connection-device-type'|'verified-access-instance'|'verified-access-group'|'verified-access-endpoint'|'verified-access-policy'|'verified-access-trust-provider'|'vpn-connection-device-type'|'vpc-block-public-access-exclusion'|'ipam-resource-discovery'|'ipam-resource-discovery-association'|'instance-connect-endpoint',
            'Value': 'string'
        },
    ]
}

Response Structure

  • (dict) –

    • NextToken (string) –

      The token to include in another request to get the next page of items. This value is null when there are no more items to return.

    • Tags (list) –

      The tags.

      • (dict) –

        Describes a tag.

        • Key (string) –

          The tag key.

        • ResourceId (string) –

          The ID of the resource.

        • ResourceType (string) –

          The resource type.

        • Value (string) –

          The tag value.

Examples

This example describes the tags for the specified instance.

response = client.describe_tags(
    Filters=[
        {
            'Name': 'resource-id',
            'Values': [
                'i-1234567890abcdef8',
            ],
        },
    ],
)

print(response)

Expected Output:

{
    'Tags': [
        {
            'Key': 'Stack',
            'ResourceId': 'i-1234567890abcdef8',
            'ResourceType': 'instance',
            'Value': 'test',
        },
        {
            'Key': 'Name',
            'ResourceId': 'i-1234567890abcdef8',
            'ResourceType': 'instance',
            'Value': 'Beta Server',
        },
    ],
    'ResponseMetadata': {
        '...': '...',
    },
}