Skip to content

STSClient.assume_role

rboto-sts==0.4.0 · Service index · Types

Model summary (excerpt): Returns a set of temporary security credentials that you can use to access Amazon Web Services resources. These temporary credentials consist of an access key ID, a secret access key, and a security token. Typically, you use AssumeRole within your account or for cross-account access. For a comparison of AssumeRole with other API operations that produce temporary credentials, see Requesting...

Install and imports

python -m pip install "rboto[sts]==0.4.0"
from rboto import STSClient
from collections.abc import Sequence
from rboto_sts.types import (
    AssumeRoleOutput,
    PolicyDescriptorType,
    ProvidedContext,
    Tag,
)

Signature

async def assume_role(
    *,
    role_arn: str,
    role_session_name: str,
    policy_arns: Sequence[PolicyDescriptorType] | None = None,
    policy: str | None = None,
    duration_seconds: int | None = None,
    tags: Sequence[Tag] | None = None,
    transitive_tag_keys: Sequence[str] | None = None,
    external_id: str | None = None,
    serial_number: str | None = None,
    token_code: str | None = None,
    source_identity: str | None = None,
    provided_contexts: Sequence[ProvidedContext] | None = None,
    minimum_session_token_size: int | None = None,
) -> AssumeRoleOutput: ...

Arguments without defaults are required. None omits an optional request argument. Static types do not validate resource existence, permissions, lengths, ranges, or conditional service requirements.

Arguments

Argument Required Model notes (excerpt)
role_arn Yes The Amazon Resource Name (ARN) of the role to assume.
role_session_name Yes An identifier for the assumed role session. Use the role session name to uniquely identify a session when the same role is assumed by different principals or for different reasons. In cross-account scenarios, the role session name is visible to, and can be logged by the account that owns the role. The role session name is also used in the ARN of the assumed role principal. This means that...
policy_arns No The Amazon Resource Names (ARNs) of the IAM managed policies that you want to use as managed session policies. The policies must exist in the same account as the role. This parameter is optional. You can provide up to 10 managed policy ARNs. However, the plaintext that you use for both inline and managed session policies can't exceed 2,048 characters. For more information about ARNs, see...
policy No An IAM policy in JSON format that you want to use as an inline session policy. This parameter is optional. Passing policies to this operation returns new temporary credentials. The resulting session's permissions are the intersection of the role's identity-based policy and the session policies. You can use the role's temporary credentials in subsequent Amazon Web Services API calls to access...
duration_seconds No The duration, in seconds, of the role session. The value specified can range from 900 seconds (15 minutes) up to the maximum session duration set for the role. The maximum session duration setting can have a value from 1 hour to 12 hours. If you specify a value higher than this setting or the administrator setting (whichever is lower), the operation fails. For example, if you specify a session...
tags No A list of session tags that you want to pass. Each session tag consists of a key name and an associated value. For more information about session tags, see Tagging Amazon Web Services STS Sessions in the IAM User Guide . This parameter is optional. You can pass up to 50 session tags. The plaintext session tag keys can’t exceed 128 characters, and the values can’t exceed 256 characters. For...
transitive_tag_keys No A list of keys for session tags that you want to set as transitive. If you set a tag key as transitive, the corresponding key and value passes to subsequent sessions in a role chain. For more information, see Chaining Roles with Session Tags in the IAM User Guide . This parameter is optional. The transitive status of a session tag does not impact its packed binary size. If you choose not to...
external_id No A unique identifier that might be required when you assume a role in another account. If the administrator of the account to which the role belongs provided you with an external ID, then provide that value in the ExternalId parameter. This value can be any string, such as a passphrase or account number. A cross-account role is usually set up to trust everyone in an account. Therefore, the...
serial_number No The identification number of the MFA device that is associated with the user who is making the AssumeRole call. Specify this value if the trust policy of the role being assumed includes a condition that requires MFA authentication. The value is either the serial number for a hardware device (such as GAHT12345678 ) or an Amazon Resource Name (ARN) for a virtual device (such as...
token_code No The value provided by the MFA device, if the trust policy of the role being assumed requires MFA. (In other words, if the policy includes a condition that tests for MFA). If the role being assumed requires MFA and if the TokenCode value is missing or expired, the AssumeRole call returns an "access denied" error. The format for this parameter, as described by its regex pattern, is a sequence of...
source_identity No The source identity specified by the principal that is calling the AssumeRole operation. The source identity value persists across chained role sessions. You can require users to specify a source identity when they assume a role. You do this by using the sts:SourceIdentity condition key in a role trust policy. You can use source identity information in CloudTrail logs to determine who took...
provided_contexts No A list of previously acquired trusted context assertions in the format of a JSON array. The trusted context assertion is signed and encrypted by Amazon Web Services STS. The following is an example of a ProvidedContext value that includes a single trusted context assertion and the ARN of the context provider from which the trusted context assertion was generated....
minimum_session_token_size No

Output

AssumeRoleOutput.

Read-only native attributes, accessed as response.field. Collection getters materialize Python values; to_dict() recursively materializes a mapping. Streams are consumed once.

Field Type Presence References
credentials CredentialsOutput | None Always present CredentialsOutput
assumed_role_user AssumedRoleUserOutput | None Always present AssumedRoleUserOutput
packed_policy_size int | None Always present —
source_identity str | None Always present —
session_token_utilization int | None Always present —
session_token_size int | None Always present —

| None means a value can be absent. Output mappings include every declared key; optional input keys may be omitted. Unknown output enum/union variants are not automatically valid inputs.

AssumeRoleOutput, PolicyDescriptorType, ProvidedContext, Tag

Follow these links for nested inputs and outputs; recursive types link back to the same type page.

Pagination and streaming

No generated paginator for this operation.

No output stream.

Errors

Import from rboto_sts.exceptions:

ExpiredTokenError, InvalidContextAssertionError, MalformedPolicyDocumentError, PackedPolicyTooLargeError, RegionDisabledError.

Other service failures use the service base error; credential, transport and timeout failures use shared errors.

Service guide · Pinned model