Skip to content

get_resources

get_resources(
    *,
    config_overrides: Optional[ResourceGroupsTaggingAPIClientConfig] = None,
    pagination_token: Optional[PaginationToken] = None,
    tag_filters: Optional[TagFilterList] = None,
    resources_per_page: Optional[ResourcesPerPage] = None,
    tags_per_page: Optional[TagsPerPage] = None,
    resource_type_filters: Optional[ResourceTypeFilterList] = None,
    include_compliance_details: Optional[IncludeComplianceDetails] = None,
    exclude_compliant_resources: Optional[ExcludeCompliantResources] = None,
    resource_arn_list: Optional[ResourceARNListForGet] = None,
) -> GetResourcesOutput

Returns all the tagged or previously tagged resources that are located in the specified Amazon Web Services Region for the account.

Depending on what information you want returned, you can also specify the following:

  • Filters that specify what tags and resource types you want returned. The response includes all tags that are associated with the requested resources.

  • Information about compliance with the account's effective tag policy. For more information on tag policies, see Tag Policies in the Organizations User Guide.

This operation supports pagination, where the response can be sent in multiple pages. You should check the PaginationToken response parameter to determine if there are additional results available to return. Repeat the query, passing the PaginationToken response parameter value as an input to the next request until you recieve a null value. A null value for PaginationToken indicates that there are no more results waiting to be returned.

GetResources does not return untagged resources.

To find untagged resources in your account, use Amazon Web Services Resource Explorer with a query that uses tag:none. For more information, see Search query syntax reference for Resource Explorer.

Parameters:

  • pagination_token (Optional[PaginationToken], default: None ) –

    Specifies a PaginationToken response value from a previous request to indicate that you want the next page of results. Leave this parameter empty in your initial request.

  • tag_filters (Optional[TagFilterList], default: None ) –

    Specifies a list of TagFilters (keys and values) to restrict the output to only those resources that have tags with the specified keys and, if included, the specified values. Each TagFilter must contain a key with values optional. A request can include up to 50 keys, and each key can include up to 20 values.

    You can't specify both this parameter and the ResourceArnList parameter in the same request. If you do, you get an Invalid Parameter exception.

    Note the following when deciding how to use TagFilters:

    • If you don't specify a TagFilter, the response includes all resources that are currently tagged or ever had a tag. Resources that were previously tagged, but do not currently have tags, are shown with an empty tag set, like this: "Tags": [].

    • If you specify more than one filter in a single request, the response returns only those resources that satisfy all filters.

    • If you specify a filter that contains more than one value for a key, the response returns resources that match any of the specified values for that key.

    • If you don't specify a value for a key, the response returns all resources that are tagged with that key, with any or no value.

      For example, for the following filters: filter1= {key1,{value1}}, filter2={key2,{value2,value3,value4}}, filter3= {key3}:

      • GetResources({filter1}) returns resources tagged with key1=value1

      • GetResources({filter2}) returns resources tagged with key2=value2 or key2=value3 or key2=value4

      • GetResources({filter3}) returns resources tagged with any tag with the key key3, and with any or no value

      • GetResources({filter1,filter2,filter3}) returns resources tagged with (key1=value1) and (key2=value2 or key2=value3 or key2=value4) and (key3, any or no value)

  • resources_per_page (Optional[ResourcesPerPage], default: None ) –

    Specifies the maximum number of results to be returned in each page. A query can return fewer than this maximum, even if there are more results still to return. You should always check the PaginationToken response value to see if there are more results. You can specify a minimum of 1 and a maximum value of 100.

  • tags_per_page (Optional[TagsPerPage], default: None ) –

    Amazon Web Services recommends using ResourcesPerPage instead of this parameter.

    A limit that restricts the number of tags (key and value pairs) returned by GetResources in paginated output. A resource with no tags is counted as having one tag (one key and value pair).

    GetResources does not split a resource and its associated tags across pages. If the specified TagsPerPage would cause such a break, a PaginationToken is returned in place of the affected resource and its tags. Use that token in another request to get the remaining data. For example, if you specify a TagsPerPage of 100 and the account has 22 resources with 10 tags each (meaning that each resource has 10 key and value pairs), the output will consist of three pages. The first page displays the first 10 resources, each with its 10 tags. The second page displays the next 10 resources, each with its 10 tags. The third page displays the remaining 2 resources, each with its 10 tags.

    You can set TagsPerPage to a minimum of 100 items up to a maximum of 500 items.

  • resource_type_filters (Optional[ResourceTypeFilterList], default: None ) –

    Specifies the resource types that you want included in the response. The format of each resource type is service[:resourceType]. For example, specifying a service of ec2 returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of ec2:instance returns only EC2 instances.

    You can't specify both this parameter and the ResourceArnList parameter in the same request. If you do, you get an Invalid Parameter exception.

    The string for each service name and resource type is the same as that embedded in a resource's Amazon Resource Name (ARN).

    For the list of services whose resources you can tag using the Resource Groups Tagging API, see Services that support the Resource Groups Tagging API. If an Amazon Web Services service isn't listed on that page, you might still be able to tag that service's resources by using that service's native tagging operations instead of using Resource Groups Tagging API operations. All tagged resources, whether the tagging used the Resource Groups Tagging API or not, are returned by the Get* operation.

    You can specify multiple resource types by using an array. The array can include up to 100 items. Note that the length constraint requirement applies to each resource type filter. For example, the following string would limit the response to only Amazon EC2 instances, Amazon S3 buckets, or any Audit Manager resource:

    ec2:instance,s3:bucket,auditmanager

  • include_compliance_details (Optional[IncludeComplianceDetails], default: None ) –

    Specifies whether to include details regarding the compliance with the effective tag policy. Set this to true to determine whether resources are compliant with the tag policy and to get details.

  • exclude_compliant_resources (Optional[ExcludeCompliantResources], default: None ) –

    Specifies whether to exclude resources that are compliant with the tag policy. Set this to true if you are interested in retrieving information on noncompliant resources only.

    You can use this parameter only if the IncludeComplianceDetails parameter is also set to true.

  • resource_arn_list (Optional[ResourceARNListForGet], default: None ) –

    Specifies a list of ARNs of resources for which you want to retrieve tag data.

    You can't specify both this parameter and the ResourceTypeFilters parameter in the same request. If you do, you get an Invalid Parameter exception.

    You can't specify both this parameter and the TagFilters parameter in the same request. If you do, you get an Invalid Parameter exception.

    You can't specify both this parameter and any of the pagination parameters (ResourcesPerPage, TagsPerPage, PaginationToken) in the same request. If you do, you get an Invalid Parameter exception.

    If a resource specified by this parameter doesn't exist, it doesn't generate an error; it simply isn't included in the response.

    An ARN (Amazon Resource Name) uniquely identifies a resource. For more information, see Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces in the Amazon Web Services General Reference.

Raises:

  • InternalServiceException –

    The request processing failed because of an unknown error, exception, or failure. You can retry the request.

  • InvalidParameterException –

    The request failed because of one of the following reasons:

    • A required parameter is missing.

    • A provided string parameter is malformed.

    • An provided parameter value is out of range.

    • The target ID is invalid, unsupported, or doesn't exist.

    • You can't access the Amazon S3 bucket for report storage. For more information, see Amazon S3 bucket policy for report storage in the Tagging Amazon Web Services resources and Tag Editor user guide.

    • The partition specified in an ARN parameter in the request doesn't match the partition where you invoked the operation. The partition is specified by the second field of the ARN.

  • PaginationTokenExpiredException –

    The request failed because the specified PaginationToken has expired. A PaginationToken is valid for a maximum of 15 minutes.

  • ThrottledException –

    The request failed because it exceeded the allowed frequency of submitted requests.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_resource_groups_tagging_api/_services/resource_groups_tagging_api.py
def get_resources(
    self,
    *,
    config_overrides: Optional[ResourceGroupsTaggingAPIClientConfig] = None,
    pagination_token: Optional[
        "capo_resource_groups_tagging_api.types.pagination_token.PaginationToken"
    ] = None,
    tag_filters: Optional[
        "capo_resource_groups_tagging_api.types.tag_filter_list.TagFilterList"
    ] = None,
    resources_per_page: Optional[
        "capo_resource_groups_tagging_api.types.resources_per_page.ResourcesPerPage"
    ] = None,
    tags_per_page: Optional[
        "capo_resource_groups_tagging_api.types.tags_per_page.TagsPerPage"
    ] = None,
    resource_type_filters: Optional[
        "capo_resource_groups_tagging_api.types.resource_type_filter_list.ResourceTypeFilterList"
    ] = None,
    include_compliance_details: Optional[
        "capo_resource_groups_tagging_api.types.include_compliance_details.IncludeComplianceDetails"
    ] = None,
    exclude_compliant_resources: Optional[
        "capo_resource_groups_tagging_api.types.exclude_compliant_resources.ExcludeCompliantResources"
    ] = None,
    resource_arn_list: Optional[
        "capo_resource_groups_tagging_api.types.resource_arn_list_for_get.ResourceARNListForGet"
    ] = None,
) -> (
    "capo_resource_groups_tagging_api.types.get_resources_output.GetResourcesOutput"
):
    """<p>Returns all the tagged or previously tagged resources that are located in the specified Amazon Web Services Region for the account. </p> <p>Depending on what information you want returned, you can also specify the following:</p> <ul> <li> <p> <i>Filters</i> that specify what tags and resource types you want returned. The response includes all tags that are associated with the requested resources.</p> </li> <li> <p>Information about compliance with the account's effective tag policy. For more information on tag policies, see <a href="https://docs.aws.amazon.com/organizations/latest/userguide/orgs_manage_policies_tag-policies.html">Tag Policies</a> in the <i>Organizations User Guide.</i> </p> </li> </ul> <p>This operation supports pagination, where the response can be sent in multiple pages. You should check the <code>PaginationToken</code> response parameter to determine if there are additional results available to return. Repeat the query, passing the <code>PaginationToken</code> response parameter value as an input to the next request until you recieve a <code>null</code> value. A null value for <code>PaginationToken</code> indicates that there are no more results waiting to be returned.</p> <note> <p> <code>GetResources</code> does not return untagged resources. </p> <p>To find untagged resources in your account, use Amazon Web Services Resource Explorer with a query that uses <code>tag:none</code>. For more information, see <a href="https://docs.aws.amazon.com/resource-explorer/latest/userguide/using-search-query-syntax.html"> Search query syntax reference for Resource Explorer</a>. </p> </note>

    Args:
        pagination_token: <p>Specifies a <code>PaginationToken</code> response value from a previous request to indicate that you want the next page of results. Leave this parameter empty in your initial request.</p>
        tag_filters: <p>Specifies a list of TagFilters (keys and values) to restrict the output to only those resources that have tags with the specified keys and, if included, the specified values. Each <code>TagFilter</code> must contain a key with values optional. A request can include up to 50 keys, and each key can include up to 20 values. </p> <p>You can't specify both this parameter and the <code>ResourceArnList</code> parameter in the same request. If you do, you get an <code>Invalid Parameter</code> exception.</p> <p>Note the following when deciding how to use TagFilters:</p> <ul> <li> <p>If you <i>don't</i> specify a <code>TagFilter</code>, the response includes all resources that are currently tagged or ever had a tag. Resources that were previously tagged, <i>but do not currently</i> have tags, are shown with an empty tag set, like this: <code>"Tags": []</code>.</p> </li> <li> <p>If you specify more than one filter in a single request, the response returns only those resources that satisfy all filters.</p> </li> <li> <p>If you specify a filter that contains more than one value for a key, the response returns resources that match <i>any</i> of the specified values for that key.</p> </li> <li> <p>If you don't specify a value for a key, the response returns all resources that are tagged with that key, with any or no value.</p> <p>For example, for the following filters: <code>filter1= {key1,{value1}}</code>, <code>filter2={key2,{value2,value3,value4}}</code>, <code>filter3= {key3}</code>:</p> <ul> <li> <p> <code>GetResources({filter1})</code> returns resources tagged with <code>key1=value1</code> </p> </li> <li> <p> <code>GetResources({filter2})</code> returns resources tagged with <code>key2=value2</code> or <code>key2=value3</code> or <code>key2=value4</code> </p> </li> <li> <p> <code>GetResources({filter3})</code> returns resources tagged with any tag with the key <code>key3</code>, and with any or no value</p> </li> <li> <p> <code>GetResources({filter1,filter2,filter3})</code> returns resources tagged with <code>(key1=value1) and (key2=value2 or key2=value3 or key2=value4) and (key3, any or no value)</code> </p> </li> </ul> </li> </ul>
        resources_per_page: <p>Specifies the maximum number of results to be returned in each page. A query can return fewer than this maximum, even if there are more results still to return. You should always check the <code>PaginationToken</code> response value to see if there are more results. You can specify a minimum of 1 and a maximum value of 100.</p>
        tags_per_page: <p>Amazon Web Services recommends using <code>ResourcesPerPage</code> instead of this parameter.</p> <p>A limit that restricts the number of tags (key and value pairs) returned by <code>GetResources</code> in paginated output. A resource with no tags is counted as having one tag (one key and value pair).</p> <p> <code>GetResources</code> does not split a resource and its associated tags across pages. If the specified <code>TagsPerPage</code> would cause such a break, a <code>PaginationToken</code> is returned in place of the affected resource and its tags. Use that token in another request to get the remaining data. For example, if you specify a <code>TagsPerPage</code> of <code>100</code> and the account has 22 resources with 10 tags each (meaning that each resource has 10 key and value pairs), the output will consist of three pages. The first page displays the first 10 resources, each with its 10 tags. The second page displays the next 10 resources, each with its 10 tags. The third page displays the remaining 2 resources, each with its 10 tags.</p> <p>You can set <code>TagsPerPage</code> to a minimum of 100 items up to a maximum of 500 items.</p>
        resource_type_filters: <p>Specifies the resource types that you want included in the response. The format of each resource type is <code>service[:resourceType]</code>. For example, specifying a service of <code>ec2</code> returns all Amazon EC2 resources (which includes EC2 instances). Specifying a resource type of <code>ec2:instance</code> returns only EC2 instances. </p> <p>You can't specify both this parameter and the <code>ResourceArnList</code> parameter in the same request. If you do, you get an <code>Invalid Parameter</code> exception.</p> <p>The string for each service name and resource type is the same as that embedded in a resource's Amazon Resource Name (ARN).</p> <note> <p>For the list of services whose resources you can tag using the Resource Groups Tagging API, see <a href="https://docs.aws.amazon.com/resourcegroupstagging/latest/APIReference/supported-services.html">Services that support the Resource Groups Tagging API</a>. If an Amazon Web Services service isn't listed on that page, you might still be able to tag that service's resources by using that service's native tagging operations instead of using Resource Groups Tagging API operations. All tagged resources, whether the tagging used the Resource Groups Tagging API or not, are returned by the <code>Get*</code> operation.</p> </note> <p>You can specify multiple resource types by using an array. The array can include up to 100 items. Note that the length constraint requirement applies to each resource type filter. For example, the following string would limit the response to only Amazon EC2 instances, Amazon S3 buckets, or any Audit Manager resource:</p> <p> <code>ec2:instance,s3:bucket,auditmanager</code> </p>
        include_compliance_details: <p>Specifies whether to include details regarding the compliance with the effective tag policy. Set this to <code>true</code> to determine whether resources are compliant with the tag policy and to get details.</p>
        exclude_compliant_resources: <p>Specifies whether to exclude resources that are compliant with the tag policy. Set this to <code>true</code> if you are interested in retrieving information on noncompliant resources only.</p> <p>You can use this parameter only if the <code>IncludeComplianceDetails</code> parameter is also set to <code>true</code>.</p>
        resource_arn_list: <p>Specifies a list of ARNs of resources for which you want to retrieve tag data.</p> <p>You can't specify both this parameter and the <code>ResourceTypeFilters</code> parameter in the same request. If you do, you get an <code>Invalid Parameter</code> exception.</p> <p>You can't specify both this parameter and the <code>TagFilters</code> parameter in the same request. If you do, you get an <code>Invalid Parameter</code> exception.</p> <p>You can't specify both this parameter and any of the pagination parameters (<code>ResourcesPerPage</code>, <code>TagsPerPage</code>, <code>PaginationToken</code>) in the same request. If you do, you get an <code>Invalid Parameter</code> exception.</p> <p>If a resource specified by this parameter doesn't exist, it doesn't generate an error; it simply isn't included in the response.</p> <p>An ARN (Amazon Resource Name) uniquely identifies a resource. For more information, see <a href="https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html">Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces</a> in the <i>Amazon Web Services General Reference</i>.</p>

    Raises:
        capo_resource_groups_tagging_api.errors.internal_service_exception.InternalServiceException: <p>The request processing failed because of an unknown error, exception, or failure. You can retry the request.</p>
        capo_resource_groups_tagging_api.errors.invalid_parameter_exception.InvalidParameterException: <p>The request failed because of one of the following reasons:</p> <ul> <li> <p>A required parameter is missing.</p> </li> <li> <p>A provided string parameter is malformed.</p> </li> <li> <p>An provided parameter value is out of range.</p> </li> <li> <p>The target ID is invalid, unsupported, or doesn't exist.</p> </li> <li> <p>You can't access the Amazon S3 bucket for report storage. For more information, see <a href="https://docs.aws.amazon.com/tag-editor/latest/userguide/tag-policies-orgs.html#bucket-policy">Amazon S3 bucket policy for report storage</a> in the <i>Tagging Amazon Web Services resources and Tag Editor</i> user guide. </p> </li> <li> <p>The partition specified in an ARN parameter in the request doesn't match the partition where you invoked the operation. The partition is specified by the second field of the ARN.</p> </li> </ul>
        capo_resource_groups_tagging_api.errors.pagination_token_expired_exception.PaginationTokenExpiredException: <p>The request failed because the specified <code>PaginationToken</code> has expired. A <code>PaginationToken</code> is valid for a maximum of 15 minutes.</p>
        capo_resource_groups_tagging_api.errors.throttled_exception.ThrottledException: <p>The request failed because it exceeded the allowed frequency of submitted requests.</p>
        capo_resource_groups_tagging_api.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_resource_groups_tagging_api.types.get_resources_input.GetResourcesInput]",
    ) -> OperationResponse[
        "capo_resource_groups_tagging_api.types.get_resources_output.GetResourcesOutput"
    ]:
        import capo_resource_groups_tagging_api._operations.resource_groups_tagging_api_20170126.get_resources

        output, http_response = (
            capo_resource_groups_tagging_api._operations.resource_groups_tagging_api_20170126.get_resources.get_resources(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("GetResources")
    )
    input_: capo_resource_groups_tagging_api.types.get_resources_input.GetResourcesInput = {}
    if pagination_token is not None:
        input_["pagination_token"] = pagination_token
    if tag_filters is not None:
        input_["tag_filters"] = tag_filters
    if resources_per_page is not None:
        input_["resources_per_page"] = resources_per_page
    if tags_per_page is not None:
        input_["tags_per_page"] = tags_per_page
    if resource_type_filters is not None:
        input_["resource_type_filters"] = resource_type_filters
    if include_compliance_details is not None:
        input_["include_compliance_details"] = include_compliance_details
    if exclude_compliant_resources is not None:
        input_["exclude_compliant_resources"] = exclude_compliant_resources
    if resource_arn_list is not None:
        input_["resource_arn_list"] = resource_arn_list

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output