Skip to content

wait_until_role_exists async

wait_until_role_exists(
    role_name: roleNameType,
    *,
    max_wait_time: float,
    min_delay: float = 1,
    max_delay: float = 120,
    config_overrides: Optional[AsyncIAMClientConfig] = None,
) -> GetRoleResponse

Wait for role_exists.

Parameters:

  • role_name (roleNameType) –

    The name of the IAM role to get information about.

    This parameter allows (through its regex pattern) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-

  • 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/async_iam.py
async def wait_until_role_exists(
    self,
    role_name: "capo_iam.types.role_name_type.roleNameType",
    *,
    max_wait_time: float,
    min_delay: float = 1,
    max_delay: float = 120,
    config_overrides: Optional[AsyncIAMClientConfig] = None,
) -> "capo_iam.types.get_role_response.GetRoleResponse":
    """Wait for role_exists.

    Args:
        role_name: <p>The name of the IAM role to get information about.</p> <p>This parameter allows (through its <a href="http://wikipedia.org/wiki/regex">regex pattern</a>) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-</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_role_response.GetRoleResponse | None" = None
        op_error: ServiceError | None = None
        try:
            op_output = await self.get_role(  # noqa: F841
                role_name, 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("role_exists", max_wait_time)
        delay = min(max_delay, min_delay * (2**attempt))
        delay = random.uniform(min_delay, delay)
        delay = min(delay, remaining)
        await anysleep(delay)
        attempt += 1