Skip to content

wait_until_policy_exists

wait_until_policy_exists(
    policy_arn: arnType,
    *,
    max_wait_time: float,
    min_delay: float = 1,
    max_delay: float = 120,
    config_overrides: Optional[IAMClientConfig] = None,
) -> GetPolicyResponse

Wait for policy_exists.

Parameters:

  • policy_arn (arnType) –

    The Amazon Resource Name (ARN) of the managed policy that you want information about.

    For more information about ARNs, see Amazon Resource Names (ARNs) in the Amazon Web Services General Reference.

  • max_wait_time (float) –

    Maximum total seconds to wait before raising WaiterTimeoutError.

  • min_delay (float, default: 1 ) –

    Minimum seconds between operation attempts (spec default 2).

  • max_delay (float, default: 120 ) –

    Maximum seconds between operation attempts (spec default 120).

Source code in docs_src/capo_iam/_services/iam.py
def wait_until_policy_exists(
    self,
    policy_arn: "capo_iam.types.arn_type.arnType",
    *,
    max_wait_time: float,
    min_delay: float = 1,
    max_delay: float = 120,
    config_overrides: Optional[IAMClientConfig] = None,
) -> "capo_iam.types.get_policy_response.GetPolicyResponse":
    """Wait for policy_exists.

    Args:
        policy_arn: <p>The Amazon Resource Name (ARN) of the managed policy that you want information about.</p> <p>For more information about ARNs, see <a href="https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html">Amazon Resource Names (ARNs)</a> in the <i>Amazon Web Services General Reference</i>.</p>
        max_wait_time: Maximum total seconds to wait before raising WaiterTimeoutError.
        min_delay: Minimum seconds between operation attempts (spec default 2).
        max_delay: Maximum seconds between operation attempts (spec default 120).
    """
    start = time.monotonic()
    attempt = 0
    while True:
        op_output: "capo_iam.types.get_policy_response.GetPolicyResponse | None" = (
            None
        )
        op_error: ServiceError | None = None
        try:
            op_output = self.get_policy(  # noqa: F841
                policy_arn, config_overrides=config_overrides
            )
        except ServiceError as e:
            op_error = e
        if op_output is not None:
            return op_output
        elif op_error is not None and op_error.code == "NoSuchEntity":
            pass
        elif op_error is not None:
            raise op_error

        elapsed = time.monotonic() - start
        remaining = max_wait_time - elapsed
        if remaining <= 0:
            raise WaiterTimeoutError("policy_exists", max_wait_time)
        delay = min(max_delay, min_delay * (2**attempt))
        delay = random.uniform(min_delay, delay)
        delay = min(delay, remaining)
        time.sleep(delay)
        attempt += 1