Skip to content

get_role_credentials async

get_role_credentials(
    tenant_id: TenantId,
    role_arn: str,
    access_type: AccessType,
    *,
    config_overrides: Optional[AsyncAccountAccessRuntimeClientConfig] = None,
    session_name: Optional[SessionName] = None,
    session_duration: Optional[int] = None,
) -> GetRoleCredentialsResponse

Returns temporary Amazon Web Services credentials for a role that you are entitled to assume within a tenant. You can use these credentials for programmatic access with the CLI or an Amazon Web Services SDK. If you aren't entitled to the role, the request fails with an AccessDeniedException error.

Parameters:

  • tenant_id (TenantId) –

    The identifier of the tenant that the request applies to. A tenant ID begins with aa- and is 3 to 24 characters long. It can contain lowercase letters, numbers, and hyphens.

  • role_arn (str) –

    The Amazon Resource Name (ARN) of the role to retrieve credentials for. You must be entitled to assume this role.

  • access_type (AccessType) –

    The type of access to request for the role. Specify PROGRAMMATIC_ACCESS to receive access key credentials for use with the CLI or an Amazon Web Services SDK.

  • session_name (Optional[SessionName], default: None ) –

    An optional name for the role session. The name can be 2 to 64 characters and can contain alphanumeric characters and the following symbols: plus (+), equal (=), comma (,), period (.), at (@), and hyphen (-). The session name appears in CloudTrail logs for the assumed role session.

  • session_duration (Optional[int], default: None ) –

    The duration, in seconds, that the returned credentials remain valid. If you don't specify a value, the service uses the default session duration. The maximum value can't exceed the maximum session duration configured for the role.

Raises:

  • AccessDeniedException –

    You are authenticated but not authorized to perform the requested action, such as assuming a role that you aren't entitled to. This error returns an HTTP 403 status code.

  • InternalServerException –

    An internal server error occurred. Retry the request. If the problem persists, contact Amazon Web Services Support. This error returns an HTTP 500 status code.

  • ThrottlingException –

    The request rate exceeded the allowed limit. Reduce your request rate, and then retry the request. This error returns an HTTP 429 status code.

  • UnauthorizedException –

    The bearer token is missing, invalid, or expired. Obtain a new token, and then retry the request. This error returns an HTTP 401 status code.

  • ValidationException –

    The request is missing a required parameter, or a parameter value doesn't satisfy its constraints, such as its length or pattern. Correct the input, and then retry the request. This error returns an HTTP 400 status code.

  • UnknownServiceError –

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

Source code in docs_src/capo_account_access_runtime/_services/async_account_access_runtime.py
async def get_role_credentials(
    self,
    tenant_id: "capo_account_access_runtime.types.tenant_id.TenantId",
    role_arn: str,
    access_type: "capo_account_access_runtime.types.access_type.AccessType",
    *,
    config_overrides: Optional[AsyncAccountAccessRuntimeClientConfig] = None,
    session_name: Optional[
        "capo_account_access_runtime.types.session_name.SessionName"
    ] = None,
    session_duration: Optional[int] = None,
) -> "capo_account_access_runtime.types.get_role_credentials_response.GetRoleCredentialsResponse":
    """<p>Returns temporary Amazon Web Services credentials for a role that you are entitled to assume within a tenant. You can use these credentials for programmatic access with the CLI or an Amazon Web Services SDK. If you aren't entitled to the role, the request fails with an <code>AccessDeniedException</code> error.</p>

    Args:
        tenant_id: <p>The identifier of the tenant that the request applies to. A tenant ID begins with <code>aa-</code> and is 3 to 24 characters long. It can contain lowercase letters, numbers, and hyphens.</p>
        role_arn: <p>The Amazon Resource Name (ARN) of the role to retrieve credentials for. You must be entitled to assume this role.</p>
        access_type: <p>The type of access to request for the role. Specify <code>PROGRAMMATIC_ACCESS</code> to receive access key credentials for use with the CLI or an Amazon Web Services SDK.</p>
        session_name: <p>An optional name for the role session. The name can be 2 to 64 characters and can contain alphanumeric characters and the following symbols: plus (+), equal (=), comma (,), period (.), at (@), and hyphen (-). The session name appears in CloudTrail logs for the assumed role session.</p>
        session_duration: <p>The duration, in seconds, that the returned credentials remain valid. If you don't specify a value, the service uses the default session duration. The maximum value can't exceed the maximum session duration configured for the role.</p>

    Raises:
        capo_account_access_runtime.errors.access_denied_exception.AccessDeniedException: <p>You are authenticated but not authorized to perform the requested action, such as assuming a role that you aren't entitled to. This error returns an HTTP 403 status code.</p>
        capo_account_access_runtime.errors.internal_server_exception.InternalServerException: <p>An internal server error occurred. Retry the request. If the problem persists, contact Amazon Web Services Support. This error returns an HTTP 500 status code.</p>
        capo_account_access_runtime.errors.throttling_exception.ThrottlingException: <p>The request rate exceeded the allowed limit. Reduce your request rate, and then retry the request. This error returns an HTTP 429 status code.</p>
        capo_account_access_runtime.errors.unauthorized_exception.UnauthorizedException: <p>The bearer token is missing, invalid, or expired. Obtain a new token, and then retry the request. This error returns an HTTP 401 status code.</p>
        capo_account_access_runtime.errors.validation_exception.ValidationException: <p>The request is missing a required parameter, or a parameter value doesn't satisfy its constraints, such as its length or pattern. Correct the input, and then retry the request. This error returns an HTTP 400 status code.</p>
        capo_account_access_runtime.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_account_access_runtime.types.get_role_credentials_request.GetRoleCredentialsRequest]",
    ) -> AsyncOperationResponse[
        "capo_account_access_runtime.types.get_role_credentials_response.GetRoleCredentialsResponse"
    ]:
        import capo_account_access_runtime._operations.aws_account_access_runtime.get_role_credentials

        (
            output,
            http_response,
        ) = await capo_account_access_runtime._operations.aws_account_access_runtime.get_role_credentials.async_get_role_credentials(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_output(
        output: "capo_account_access_runtime.types.get_role_credentials_response.GetRoleCredentialsResponse",
    ) -> dict[str, Any]:
        import capo_account_access_runtime.types.get_role_credentials_response

        return capo_account_access_runtime.types.get_role_credentials_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("GetRoleCredentials", redact_output=_redact_output),
    )
    input_: capo_account_access_runtime.types.get_role_credentials_request.GetRoleCredentialsRequest = {
        "tenant_id": tenant_id,
        "role_arn": role_arn,
        "access_type": access_type,
    }
    if session_name is not None:
        input_["session_name"] = session_name
    if session_duration is not None:
        input_["session_duration"] = session_duration

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output