Skip to content

describe_compliance_by_resource

describe_compliance_by_resource(
    *,
    config_overrides: Optional[ConfigServiceClientConfig] = None,
    resource_type: Optional[StringWithCharLimit256] = None,
    resource_id: Optional[BaseResourceId] = None,
    compliance_types: Optional[ComplianceTypes] = None,
    limit: Optional[Limit] = None,
    next_token: Optional[NextToken] = None,
) -> DescribeComplianceByResourceResponse

Indicates whether the specified Amazon Web Services resources are compliant. If a resource is noncompliant, this operation returns the number of Config rules that the resource does not comply with.

A resource is compliant if it complies with all the Config rules that evaluate it. It is noncompliant if it does not comply with one or more of these rules.

If Config has no current evaluation results for the resource, it returns INSUFFICIENT_DATA. This result might indicate one of the following conditions about the rules that evaluate the resource:

  • Config has never invoked an evaluation for the rule. To check whether it has, use the DescribeConfigRuleEvaluationStatus action to get the LastSuccessfulInvocationTime and LastFailedInvocationTime.

  • The rule's Lambda function is failing to send evaluation results to Config. Verify that the role that you assigned to your configuration recorder includes the config:PutEvaluations permission. If the rule is a custom rule, verify that the Lambda execution role includes the config:PutEvaluations permission.

  • The rule's Lambda function has returned NOT_APPLICABLE for all evaluation results. This can occur if the resources were deleted or removed from the rule's scope.

Parameters:

  • resource_type (Optional[StringWithCharLimit256], default: None ) –

    The types of Amazon Web Services resources for which you want compliance information (for example, AWS::EC2::Instance). For this operation, you can specify that the resource type is an Amazon Web Services account by specifying AWS::::Account.

  • resource_id (Optional[BaseResourceId], default: None ) –

    The ID of the Amazon Web Services resource for which you want compliance information. You can specify only one resource ID. If you specify a resource ID, you must also specify a type for ResourceType.

  • compliance_types (Optional[ComplianceTypes], default: None ) –

    Filters the results by compliance.

  • limit (Optional[Limit], default: None ) –

    The maximum number of evaluation results returned on each page. The default is 10. You cannot specify a number greater than 100. If you specify 0, Config uses the default.

  • next_token (Optional[NextToken], default: None ) –

    The nextToken string returned on a previous page that you use to get the next page of results in a paginated response.

Raises:

  • InvalidNextTokenException –

    The specified next token is not valid. Specify the nextToken string that was returned in the previous response to get the next page of results.

  • InvalidParameterValueException –

    One or more of the specified parameters are not valid. Verify that your parameters are valid and try again.

  • UnknownServiceError –

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

Source code in docs_src/capo_config_service/_services/config_service.py
def describe_compliance_by_resource(
    self,
    *,
    config_overrides: Optional[ConfigServiceClientConfig] = None,
    resource_type: Optional[
        "capo_config_service.types.string_with_char_limit256.StringWithCharLimit256"
    ] = None,
    resource_id: Optional[
        "capo_config_service.types.base_resource_id.BaseResourceId"
    ] = None,
    compliance_types: Optional[
        "capo_config_service.types.compliance_types.ComplianceTypes"
    ] = None,
    limit: Optional["capo_config_service.types.limit.Limit"] = None,
    next_token: Optional["capo_config_service.types.next_token.NextToken"] = None,
) -> "capo_config_service.types.describe_compliance_by_resource_response.DescribeComplianceByResourceResponse":
    """<p>Indicates whether the specified Amazon Web Services resources are compliant. If a resource is noncompliant, this operation returns the number of Config rules that the resource does not comply with.</p> <p>A resource is compliant if it complies with all the Config rules that evaluate it. It is noncompliant if it does not comply with one or more of these rules.</p> <p>If Config has no current evaluation results for the resource, it returns <code>INSUFFICIENT_DATA</code>. This result might indicate one of the following conditions about the rules that evaluate the resource:</p> <ul> <li> <p>Config has never invoked an evaluation for the rule. To check whether it has, use the <code>DescribeConfigRuleEvaluationStatus</code> action to get the <code>LastSuccessfulInvocationTime</code> and <code>LastFailedInvocationTime</code>.</p> </li> <li> <p>The rule's Lambda function is failing to send evaluation results to Config. Verify that the role that you assigned to your configuration recorder includes the <code>config:PutEvaluations</code> permission. If the rule is a custom rule, verify that the Lambda execution role includes the <code>config:PutEvaluations</code> permission.</p> </li> <li> <p>The rule's Lambda function has returned <code>NOT_APPLICABLE</code> for all evaluation results. This can occur if the resources were deleted or removed from the rule's scope.</p> </li> </ul>

    Args:
        resource_type: <p>The types of Amazon Web Services resources for which you want compliance information (for example, <code>AWS::EC2::Instance</code>). For this operation, you can specify that the resource type is an Amazon Web Services account by specifying <code>AWS::::Account</code>.</p>
        resource_id: <p>The ID of the Amazon Web Services resource for which you want compliance information. You can specify only one resource ID. If you specify a resource ID, you must also specify a type for <code>ResourceType</code>.</p>
        compliance_types: <p>Filters the results by compliance.</p>
        limit: <p>The maximum number of evaluation results returned on each page. The default is 10. You cannot specify a number greater than 100. If you specify 0, Config uses the default.</p>
        next_token: <p>The <code>nextToken</code> string returned on a previous page that you use to get the next page of results in a paginated response.</p>

    Raises:
        capo_config_service.errors.invalid_next_token_exception.InvalidNextTokenException: <p>The specified next token is not valid. Specify the <code>nextToken</code> string that was returned in the previous response to get the next page of results.</p>
        capo_config_service.errors.invalid_parameter_value_exception.InvalidParameterValueException: <p>One or more of the specified parameters are not valid. Verify that your parameters are valid and try again.</p>
        capo_config_service.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_config_service.types.describe_compliance_by_resource_request.DescribeComplianceByResourceRequest]",
    ) -> OperationResponse[
        "capo_config_service.types.describe_compliance_by_resource_response.DescribeComplianceByResourceResponse"
    ]:
        import capo_config_service._operations.starling_dove_service.describe_compliance_by_resource

        output, http_response = (
            capo_config_service._operations.starling_dove_service.describe_compliance_by_resource.describe_compliance_by_resource(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DescribeComplianceByResource")
    )
    input_: capo_config_service.types.describe_compliance_by_resource_request.DescribeComplianceByResourceRequest = {}
    if resource_type is not None:
        input_["resource_type"] = resource_type
    if resource_id is not None:
        input_["resource_id"] = resource_id
    if compliance_types is not None:
        input_["compliance_types"] = compliance_types
    if limit is not None:
        input_["limit"] = limit
    if next_token is not None:
        input_["next_token"] = next_token

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