Skip to content

remove_targets

remove_targets(
    rule: RuleName,
    ids: TargetIdList,
    *,
    config_overrides: Optional[EventBridgeClientConfig] = None,
    event_bus_name: Optional[EventBusNameOrArn] = None,
    force: Optional[Boolean] = None,
) -> RemoveTargetsResponse

Removes the specified targets from the specified rule. When the rule is triggered, those targets are no longer be invoked.

A successful execution of RemoveTargets doesn't guarantee all targets are removed from the rule, it means that the target(s) listed in the request are removed.

When you remove a target, when the associated rule triggers, removed targets might continue to be invoked. Allow a short period of time for changes to take effect.

This action can partially fail if too many requests are made at the same time. If that happens, FailedEntryCount is non-zero in the response and each entry in FailedEntries provides the ID of the failed target and the error code.

The maximum number of entries per request is 10.

Parameters:

  • rule (RuleName) –

    The name of the rule.

  • event_bus_name (Optional[EventBusNameOrArn], default: None ) –

    The name or ARN of the event bus associated with the rule. If you omit this, the default event bus is used.

  • ids (TargetIdList) –

    The IDs of the targets to remove from the rule.

  • force (Optional[Boolean], default: None ) –

    If this is a managed rule, created by an Amazon Web Services service on your behalf, you must specify Force as True to remove targets. This parameter is ignored for rules that are not managed rules. You can check whether a rule is a managed rule by using DescribeRule or ListRules and checking the ManagedBy field of the response.

Raises:

  • ConcurrentModificationException –

    There is concurrent modification on a rule, target, archive, or replay.

  • InternalException –

    This exception occurs due to unexpected causes.

  • ManagedRuleException –

    This rule was created by an Amazon Web Services service on behalf of your account. It is managed by that service. If you see this error in response to DeleteRule or RemoveTargets, you can use the Force parameter in those calls to delete the rule or remove targets from the rule. You cannot modify these managed rules by using DisableRule, EnableRule, PutTargets, PutRule, TagResource, or UntagResource.

  • ResourceNotFoundException –

    An entity that you specified does not exist.

  • UnknownServiceError –

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

Source code in docs_src/capo_eventbridge/_services/event_bridge.py
def remove_targets(
    self,
    rule: "capo_eventbridge.types.rule_name.RuleName",
    ids: "capo_eventbridge.types.target_id_list.TargetIdList",
    *,
    config_overrides: Optional[EventBridgeClientConfig] = None,
    event_bus_name: Optional[
        "capo_eventbridge.types.event_bus_name_or_arn.EventBusNameOrArn"
    ] = None,
    force: Optional["capo_eventbridge.types.boolean.Boolean"] = None,
) -> "capo_eventbridge.types.remove_targets_response.RemoveTargetsResponse":
    """<p>Removes the specified targets from the specified rule. When the rule is triggered, those targets are no longer be invoked.</p> <note> <p>A successful execution of <code>RemoveTargets</code> doesn't guarantee all targets are removed from the rule, it means that the target(s) listed in the request are removed.</p> </note> <p>When you remove a target, when the associated rule triggers, removed targets might continue to be invoked. Allow a short period of time for changes to take effect.</p> <p>This action can partially fail if too many requests are made at the same time. If that happens, <code>FailedEntryCount</code> is non-zero in the response and each entry in <code>FailedEntries</code> provides the ID of the failed target and the error code.</p> <p>The maximum number of entries per request is 10.</p>

    Args:
        rule: <p>The name of the rule.</p>
        event_bus_name: <p>The name or ARN of the event bus associated with the rule. If you omit this, the default event bus is used.</p>
        ids: <p>The IDs of the targets to remove from the rule.</p>
        force: <p>If this is a managed rule, created by an Amazon Web Services service on your behalf, you must specify <code>Force</code> as <code>True</code> to remove targets. This parameter is ignored for rules that are not managed rules. You can check whether a rule is a managed rule by using <code>DescribeRule</code> or <code>ListRules</code> and checking the <code>ManagedBy</code> field of the response.</p>

    Raises:
        capo_eventbridge.errors.concurrent_modification_exception.ConcurrentModificationException: <p>There is concurrent modification on a rule, target, archive, or replay.</p>
        capo_eventbridge.errors.internal_exception.InternalException: <p>This exception occurs due to unexpected causes.</p>
        capo_eventbridge.errors.managed_rule_exception.ManagedRuleException: <p>This rule was created by an Amazon Web Services service on behalf of your account. It is managed by that service. If you see this error in response to <code>DeleteRule</code> or <code>RemoveTargets</code>, you can use the <code>Force</code> parameter in those calls to delete the rule or remove targets from the rule. You cannot modify these managed rules by using <code>DisableRule</code>, <code>EnableRule</code>, <code>PutTargets</code>, <code>PutRule</code>, <code>TagResource</code>, or <code>UntagResource</code>. </p>
        capo_eventbridge.errors.resource_not_found_exception.ResourceNotFoundException: <p>An entity that you specified does not exist.</p>
        capo_eventbridge.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_eventbridge.types.remove_targets_request.RemoveTargetsRequest]",
    ) -> OperationResponse[
        "capo_eventbridge.types.remove_targets_response.RemoveTargetsResponse"
    ]:
        import capo_eventbridge._operations.aws_events.remove_targets

        output, http_response = (
            capo_eventbridge._operations.aws_events.remove_targets.remove_targets(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("RemoveTargets")
    )
    input_: capo_eventbridge.types.remove_targets_request.RemoveTargetsRequest = {
        "rule": rule,
        "ids": ids,
    }
    if event_bus_name is not None:
        input_["event_bus_name"] = event_bus_name
    if force is not None:
        input_["force"] = force

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