2026/11/19 - AWS Security Token Service - 1 new 3 updated api methods
Changes AWS STS adds GetScopedCredentials and expands Trusted Identity Propagation (TIP) to IAM federation and IAM Roles Anywhere. GetScopedCredentials reduces an existing session's permissions and duration. TIP carries verified user or workload identity for authorization and CloudTrail auditing.
Returns a set of temporary security credentials that are scoped down from the caller's existing temporary security credentials. GetScopedCredentials preserves the caller's identity while narrowing the permissions and optionally shortening the session lifetime.
For a comparison of GetScopedCredentials with the other API operations that produce temporary security credentials, see Requesting Temporary Security Credentials and Compare STS credentials in the IAM User Guide.
Credential requirements
You can only call GetScopedCredentials with temporary security credentials, for example, credentials from an assumed role or a federated session. You cannot call it with IAM user credentials or root credentials. If you want to scope down IAM user credentials, first call GetSessionToken to get temporary security credentials, and then call GetScopedCredentials with those credentials.
See also: AWS API Documentation
Request Syntax
client.get_scoped_credentials(
Policy='string',
DurationSeconds=123,
MinimumSessionTokenSize=123,
ScopedSessionDescription='string'
)
string
An IAM policy in JSON format that you want to use as a scope down policy.
A request must provide at least one of Policy or DurationSeconds. Both parameters are optional individually, but you must specify at least one of them.
The resulting session's permissions are the intersection of the calling session's existing permissions and this scope down policy. You cannot use this scope down policy to grant more permissions than the calling session already has.
The plaintext of the scope down policy cannot exceed 2,048 characters. The JSON policy characters can be any ASCII character from the space character to the end of the valid character list (u0020 through u00FF). It can also include the tab (u0009), linefeed (u000A), and carriage return (u000D) characters.
integer
The duration, in seconds, of the resulting scoped down credentials. The value can range from 1 second to 129,600 seconds (36 hours).
If you do not specify this value, the scoped down credentials will inherit the calling session's expiration time.
integer
The minimum size, in bytes, of the session token that STS issues for the request. STS increases the session token to at least this size, regardless of its actual content. The value must not exceed 4,096 bytes. When set to 0 or not specified, the session token size is unchanged.
string
A caller-supplied description of the scoped session. The value cannot exceed 256 characters. This description is logged to CloudTrail for the request, so you can use it to record the purpose of the scoped session.
dict
Response Syntax
{
'Credentials': {
'AccessKeyId': 'string',
'SecretAccessKey': 'string',
'SessionToken': 'string',
'Expiration': datetime(2015, 1, 1)
},
'SessionInfo': {
'ScopedSessionId': 'string',
'Arn': 'string'
},
'SessionTokenUtilization': 123,
'SessionTokenSize': 123,
'ScopedPoliciesCount': 123,
'SourceIdentity': 'string'
}
Response Structure
(dict) --
Contains the response to a successful GetScopedCredentials request, including the scoped-down temporary Amazon Web Services credentials and metadata about the resulting session.
Credentials (dict) --
The temporary security credentials for the scoped down session, which include an access key ID, a secret access key, and a security token.
AccessKeyId (string) --
The access key ID that identifies the temporary security credentials.
SecretAccessKey (string) --
The secret access key that can be used to sign requests.
SessionToken (string) --
The token that users must pass to the service API to use the temporary credentials.
Expiration (datetime) --
The date on which the current credentials expire.
SessionInfo (dict) --
Metadata about the resulting scoped session, including its identifier and ARN. Because the identity does not change, the identifiers reflect the same principal and session name as the calling session.
ScopedSessionId (string) --
A unique identifier for the scoped session. Because the identity is preserved, this identifies the same principal as the calling session.
Arn (string) --
The ARN of the scoped session. For more information about ARNs and how to use them in policies, see IAM Identifiers in the IAM User Guide.
SessionTokenUtilization (integer) --
The percentage (0-100) of the maximum allowed session token size that the returned session token consumes.
SessionTokenSize (integer) --
The size, in bytes, of the session token returned in the Credentials for this response.
ScopedPoliciesCount (integer) --
GetScopedCredentials can be called recursively and ScopedPoliciesCount specifies the number of scope down policies applied to the session. Each recursive call adds another scope down policy layer. A maximum of 3 scope down policy layers are allowed per session. If a session already has 3 GetScopedCredentials scope-down policies, a subsequent GetScopedCredentials call that supplies a Policy (attempting to append a fourth scope-down policy) is denied.
SourceIdentity (string) --
The source identity of the calling session, carried forward unchanged. This operation never sets or modifies the source identity; it reflects the value established when the source identity was first set. For more information, see Monitor and control actions taken with assumed roles in the IAM User Guide.
{'TrustedIdentityPropagationContext': {'OriginIdentity': {'FederatedProviderArn': 'string',
'Issuer': 'string',
'Subject': 'string',
'SubjectType': 'string'},
'TransactionContext': {'IdentityProvider': {'string': 'string'}}}}
Returns a set of temporary security credentials for users who have been authenticated via a SAML authentication response. This operation provides a mechanism for tying an enterprise identity store or directory to role-based Amazon Web Services access without user-specific credentials or configuration. For a comparison of AssumeRoleWithSAML with the other API operations that produce temporary credentials, see Requesting Temporary Security Credentials and Compare STS credentials in the IAM User Guide.
The temporary security credentials returned by this operation consist of an access key ID, a secret access key, and a security token. Applications can use these temporary security credentials to sign calls to Amazon Web Services services.
Session Duration
By default, the temporary security credentials created by AssumeRoleWithSAML last for one hour. However, you can use the optional DurationSeconds parameter to specify the duration of your session. Your role session lasts for the duration that you specify, or until the time specified in the SAML authentication response's SessionNotOnOrAfter value, whichever is shorter. You can provide a DurationSeconds value from 900 seconds (15 minutes) up to the maximum session duration setting for the role. This setting can have a value from 1 hour to 12 hours. To learn how to view the maximum value for your role, see View the Maximum Session Duration Setting for a Role in the IAM User Guide. The maximum session duration limit applies when you use the AssumeRole* API operations or the assume-role* CLI commands. However the limit does not apply when you use those operations to create a console URL. For more information, see Using IAM Roles in the IAM User Guide.
Permissions
The temporary security credentials created by AssumeRoleWithSAML can be used to make API calls to any Amazon Web Services service with the following exception: you cannot call the STS GetFederationToken or GetSessionToken API operations.
(Optional) You can pass inline or managed session policies to this operation. You can pass a single JSON policy document to use as an inline session policy. You can also specify up to 10 managed policy Amazon Resource Names (ARNs) to use as managed session policies. The plaintext that you use for both inline and managed session policies can't exceed 2,048 characters. 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 resources in the account that owns the role. You cannot use session policies to grant more permissions than those allowed by the identity-based policy of the role that is being assumed. For more information, see Session Policies in the IAM User Guide.
Calling AssumeRoleWithSAML does not require the use of Amazon Web Services security credentials. The identity of the caller is validated by using keys in the metadata document that is uploaded for the SAML provider entity for your identity provider.
Tags
(Optional) You can configure your IdP to pass attributes into your SAML assertion as session tags. Each session tag consists of a key name and an associated value. For more information about session tags, see Passing Session Tags in STS in the IAM User Guide.
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 these and additional limits, see IAM and STS Character Limits in the IAM User Guide.
You can pass a session tag with the same key as a tag that is attached to the role. When you do, session tags override the role's tags with the same key.
An administrator must grant you the permissions necessary to pass session tags. The administrator can also create granular permissions to allow you to pass only specific session tags. For more information, see Tutorial: Using Tags for Attribute-Based Access Control in the IAM User Guide.
You can set the session tags as transitive. Transitive tags persist during role chaining. For more information, see Chaining Roles with Session Tags in the IAM User Guide.
SAML Configuration
Before your application can call AssumeRoleWithSAML, you must configure your SAML identity provider (IdP) to issue the claims required by Amazon Web Services. Additionally, you must use Identity and Access Management (IAM) to create a SAML provider entity in your Amazon Web Services account that represents your identity provider. You must also create an IAM role that specifies this SAML provider in its trust policy.
For more information, see the following resources:
About SAML 2.0-based Federation in the IAM User Guide.
Creating SAML Identity Providers in the IAM User Guide.
Configuring a Relying Party and Claims in the IAM User Guide.
Creating a Role for SAML 2.0 Federation in the IAM User Guide.
See also: AWS API Documentation
Request Syntax
client.assume_role_with_saml(
RoleArn='string',
PrincipalArn='string',
SAMLAssertion='string',
PolicyArns=[
{
'arn': 'string'
},
],
Policy='string',
DurationSeconds=123,
MinimumSessionTokenSize=123
)
string
[REQUIRED]
The Amazon Resource Name (ARN) of the role that the caller is assuming.
string
[REQUIRED]
The Amazon Resource Name (ARN) of the SAML provider in IAM that describes the IdP.
string
[REQUIRED]
The base64 encoded SAML authentication response provided by the IdP.
For more information, see Configuring a Relying Party and Adding Claims in the IAM User Guide.
list
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 Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces in the Amazon Web Services General Reference.
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 resources in the account that owns the role. You cannot use session policies to grant more permissions than those allowed by the identity-based policy of the role that is being assumed. For more information, see Session Policies in the IAM User Guide.
(dict) --
A reference to the IAM managed policy that is passed as a session policy for a role session or a federated user session.
arn (string) --
The Amazon Resource Name (ARN) of the IAM managed policy to use as a session policy for the role. For more information about ARNs, see Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces in the Amazon Web Services General Reference.
string
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 resources in the account that owns the role. You cannot use session policies to grant more permissions than those allowed by the identity-based policy of the role that is being assumed. For more information, see Session Policies in the IAM User Guide.
The plaintext that you use for both inline and managed session policies can't exceed 2,048 characters. The JSON policy characters can be any ASCII character from the space character to the end of the valid character list (u0020 through u00FF). It can also include the tab (u0009), linefeed (u000A), and carriage return (u000D) characters.
For more information about role session permissions, see Session policies.
integer
The duration, in seconds, of the role session. Your role session lasts for the duration that you specify for the DurationSeconds parameter, or until the time specified in the SAML authentication response's SessionNotOnOrAfter value, whichever is shorter. You can provide a DurationSeconds value from 900 seconds (15 minutes) up to the maximum session duration setting for the role. This setting can have a value from 1 hour to 12 hours. If you specify a value higher than this setting, the operation fails. For example, if you specify a session duration of 12 hours, but your administrator set the maximum session duration to 6 hours, your operation fails. To learn how to view the maximum value for your role, see View the Maximum Session Duration Setting for a Role in the IAM User Guide.
By default, the value is set to 3600 seconds.
integer
The minimum size, in bytes, of the session token that STS issues for the request. STS increases the session token to at least this size, regardless of its actual content. The value must not exceed 4,096 bytes. When set to 0 or not specified, the session token size is unchanged.
dict
Response Syntax
{
'Credentials': {
'AccessKeyId': 'string',
'SecretAccessKey': 'string',
'SessionToken': 'string',
'Expiration': datetime(2015, 1, 1)
},
'AssumedRoleUser': {
'AssumedRoleId': 'string',
'Arn': 'string'
},
'PackedPolicySize': 123,
'Subject': 'string',
'SubjectType': 'string',
'Issuer': 'string',
'Audience': 'string',
'NameQualifier': 'string',
'SourceIdentity': 'string',
'SessionTokenUtilization': 123,
'SessionTokenSize': 123,
'TrustedIdentityPropagationContext': {
'OriginIdentity': {
'Subject': 'string',
'SubjectType': 'string',
'Issuer': 'string',
'FederatedProviderArn': 'string'
},
'TransactionContext': {
'IdentityProvider': {
'string': 'string'
}
}
}
}
Response Structure
(dict) --
Contains the response to a successful AssumeRoleWithSAML request, including temporary Amazon Web Services credentials that can be used to make Amazon Web Services requests.
Credentials (dict) --
The temporary security credentials, which include an access key ID, a secret access key, and a security (or session) token.
AccessKeyId (string) --
The access key ID that identifies the temporary security credentials.
SecretAccessKey (string) --
The secret access key that can be used to sign requests.
SessionToken (string) --
The token that users must pass to the service API to use the temporary credentials.
Expiration (datetime) --
The date on which the current credentials expire.
AssumedRoleUser (dict) --
The identifiers for the temporary security credentials that the operation returns.
AssumedRoleId (string) --
A unique identifier that contains the role ID and the role session name of the role that is being assumed. The role ID is generated by Amazon Web Services when the role is created.
Arn (string) --
The ARN of the temporary security credentials that are returned from the AssumeRole action. For more information about ARNs and how to use them in policies, see IAM Identifiers in the IAM User Guide.
PackedPolicySize (integer) --
The percentage (0-100) of the maximum allowed session token size that the returned session token consumes.
This field is deprecated. Use SessionTokenUtilization instead.
Subject (string) --
The value of the NameID element in the Subject element of the SAML assertion.
This is not the trusted identity propagation subject ( aws:OriginIdentity/Subject). When the session carries trusted identity propagation context, that value is returned in TrustedIdentityPropagationContext.
SubjectType (string) --
The format of the name ID, as defined by the Format attribute in the NameID element of the SAML assertion. Typical examples of the format are transient or persistent.
If the format includes the prefix urn:oasis:names:tc:SAML:2.0:nameid-format, that prefix is removed. For example, urn:oasis:names:tc:SAML:2.0:nameid-format:transient is returned as transient. If the format includes any other prefix, the format is returned with no modifications.
This is not the trusted identity propagation subject type ( aws:OriginIdentity/SubjectType). When the session carries trusted identity propagation context, that value is returned in TrustedIdentityPropagationContext.
Issuer (string) --
The value of the Issuer element of the SAML assertion.
This is not the trusted identity propagation issuer ( aws:OriginIdentity/Issuer). When the session carries trusted identity propagation context, that value is returned in TrustedIdentityPropagationContext.
Audience (string) --
The value of the Recipient attribute of the SubjectConfirmationData element of the SAML assertion.
NameQualifier (string) --
A hash value based on the concatenation of the following:
The Issuer response value.
The Amazon Web Services account ID.
The friendly name (the last part of the ARN) of the SAML provider in IAM.
The combination of NameQualifier and Subject can be used to uniquely identify a user.
The following pseudocode shows how the hash value is calculated:
BASE64 ( SHA1 ( "https://example.com/saml" + "123456789012" + "/MySAMLIdP" ) )
SourceIdentity (string) --
The value in the SourceIdentity attribute in the SAML assertion. The source identity value persists across chained role sessions.
You can require users to set a source identity value when they assume a role. You do this by using the sts:SourceIdentity condition key in a role trust policy. That way, actions that are taken with the role are associated with that user. After the source identity is set, the value cannot be changed. It is present in the request for all actions that are taken by the role and persists across chained role sessions. You can configure your SAML identity provider to use an attribute associated with your users, like user name or email, as the source identity when calling AssumeRoleWithSAML. You do this by adding an attribute to the SAML assertion. For more information about using source identity, see Monitor and control actions taken with assumed roles in the IAM User Guide.
The regex used to validate this parameter is a string of characters consisting of upper- and lower-case alphanumeric characters with no spaces. You can also include underscores or any of the following characters: =,.@-
SessionTokenUtilization (integer) --
The percentage (0-100) of the maximum allowed session token size that the returned session token consumes.
SessionTokenSize (integer) --
The size, in bytes, of the session token returned in the Credentials for this response.
TrustedIdentityPropagationContext (dict) --
The trusted identity propagation context that Amazon Web Services STS set in the session from the SAML assertion, through the context provider attached to the SAML identity provider. It is present only when Amazon Web Services STS set such context in the session. It contains the aws:OriginIdentity/Subject, aws:OriginIdentity/SubjectType, aws:OriginIdentity/Issuer and aws:OriginIdentity/FederatedProviderArn keys and the aws:TransactionContext/IdentityProvider/* keys that Amazon Web Services STS set in the session. Other keys in the session, such as aws:IdentityCenterInstanceArn and aws:IdentityStoreArn for an identity provider with an Identity Center instance attached, are not returned.
Its OriginIdentity members share the names Subject, SubjectType and Issuer with members of this response but carry the trusted identity propagation values, which differ from the SAML assertion values.
It is not returned when the SAML assertion is encrypted, even though the session carries the context.
This element contains information about the end user. Do not log it.
OriginIdentity (dict) --
The identity of the end user on whose behalf the session acts.
Subject (string) --
The value of the aws:OriginIdentity/Subject key: the end user's identifier, taken from the token claim that the context provider maps as the subject.
SubjectType (string) --
The value of the aws:OriginIdentity/SubjectType key, which indicates whether the end user is a person ( user) or a non-human caller such as an application or service ( workload).
Issuer (string) --
The value of the aws:OriginIdentity/Issuer key. For AssumeRoleWithWebIdentity, this is the iss claim of the token without the https:// prefix. For AssumeRoleWithSAML, this is a hash of the key that signed the SAML assertion, not the Issuer element of the assertion.
FederatedProviderArn (string) --
The value of the aws:OriginIdentity/FederatedProviderArn key: the ARN of the IAM identity provider that the request federated through.
TransactionContext (dict) --
Additional claims about the request that the identity provider asserted.
IdentityProvider (dict) --
The session's aws:TransactionContext/IdentityProvider/* keys, keyed by the part of the key name after aws:TransactionContext/IdentityProvider/. Each value is up to 128 characters.
The number of entries is bounded twice. IAM limits how many keys a context provider maps when you configure it on the identity provider, and Amazon Web Services STS rejects a session whose session token exceeds the maximum size with PackedPolicyTooLarge.
(string) --
(string) --
{'TrustedIdentityPropagationContext': {'OriginIdentity': {'FederatedProviderArn': 'string',
'Issuer': 'string',
'Subject': 'string',
'SubjectType': 'string'},
'TransactionContext': {'IdentityProvider': {'string': 'string'}}}}
Returns a set of temporary security credentials for users who have been authenticated in a mobile or web application with a web identity provider. Example providers include the OAuth 2.0 providers Login with Amazon and Facebook, or any OpenID Connect-compatible identity provider such as Google or Amazon Cognito federated identities.
Calling AssumeRoleWithWebIdentity does not require the use of Amazon Web Services security credentials. Therefore, you can distribute an application (for example, on mobile devices) that requests temporary security credentials without including long-term Amazon Web Services credentials in the application. You also don't need to deploy server-based proxy services that use long-term Amazon Web Services credentials. Instead, the identity of the caller is validated by using a token from the web identity provider. For a comparison of AssumeRoleWithWebIdentity with the other API operations that produce temporary credentials, see Requesting Temporary Security Credentials and Compare STS credentials in the IAM User Guide.
The temporary security credentials returned by this API consist of an access key ID, a secret access key, and a security token. Applications can use these temporary security credentials to sign calls to Amazon Web Services service API operations.
Session Duration
By default, the temporary security credentials created by AssumeRoleWithWebIdentity last for one hour. However, you can use the optional DurationSeconds parameter to specify the duration of your session. You can provide a value from 900 seconds (15 minutes) up to the maximum session duration setting for the role. This setting can have a value from 1 hour to 12 hours. To learn how to view the maximum value for your role, see Update the maximum session duration for a role in the IAM User Guide. The maximum session duration limit applies when you use the AssumeRole* API operations or the assume-role* CLI commands. However the limit does not apply when you use those operations to create a console URL. For more information, see Using IAM Roles in the IAM User Guide.
Permissions
The temporary security credentials created by AssumeRoleWithWebIdentity can be used to make API calls to any Amazon Web Services service with the following exception: you cannot call the STS GetFederationToken or GetSessionToken API operations.
(Optional) You can pass inline or managed session policies to this operation. You can pass a single JSON policy document to use as an inline session policy. You can also specify up to 10 managed policy Amazon Resource Names (ARNs) to use as managed session policies. The plaintext that you use for both inline and managed session policies can't exceed 2,048 characters. 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 resources in the account that owns the role. You cannot use session policies to grant more permissions than those allowed by the identity-based policy of the role that is being assumed. For more information, see Session Policies in the IAM User Guide.
Tags
(Optional) You can configure your IdP to pass attributes into your web identity token as session tags. Each session tag consists of a key name and an associated value. For more information about session tags, see Passing session tags using AssumeRoleWithWebIdentity in the IAM User Guide.
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 these and additional limits, see IAM and STS Character Limits in the IAM User Guide.
You can pass a session tag with the same key as a tag that is attached to the role. When you do, the session tag overrides the role tag with the same key.
An administrator must grant you the permissions necessary to pass session tags. The administrator can also create granular permissions to allow you to pass only specific session tags. For more information, see Tutorial: Using Tags for Attribute-Based Access Control in the IAM User Guide.
You can set the session tags as transitive. Transitive tags persist during role chaining. For more information, see Chaining Roles with Session Tags in the IAM User Guide.
Identities
Before your application can call AssumeRoleWithWebIdentity, you must have an identity token from a supported identity provider and create a role that the application can assume. The role that your application assumes must trust the identity provider that is associated with the identity token. In other words, the identity provider must be specified in the role's trust policy.
For more information about how to use OIDC federation and the AssumeRoleWithWebIdentity API, see the following resources:
Using Web Identity Federation API Operations for Mobile Apps and Federation Through a Web-based Identity Provider.
Amazon Web Services SDK for iOS Developer Guide and Amazon Web Services SDK for Android Developer Guide. These toolkits contain sample apps that show how to invoke the identity providers. The toolkits then show how to use the information from these providers to get and use temporary security credentials.
See also: AWS API Documentation
Request Syntax
client.assume_role_with_web_identity(
RoleArn='string',
RoleSessionName='string',
WebIdentityToken='string',
ProviderId='string',
PolicyArns=[
{
'arn': 'string'
},
],
Policy='string',
DurationSeconds=123,
MinimumSessionTokenSize=123
)
string
[REQUIRED]
The Amazon Resource Name (ARN) of the role that the caller is assuming.
string
[REQUIRED]
An identifier for the assumed role session. Typically, you pass the name or identifier that is associated with the user who is using your application. That way, the temporary security credentials that your application will use are associated with that user. This session name is included as part of the ARN and assumed role ID in the AssumedRoleUser response element.
For security purposes, administrators can view this field in CloudTrail logs to help identify who performed an action in Amazon Web Services. Your administrator might require that you specify your user name as the session name when you assume the role. For more information, see sts:RoleSessionName.
The regex used to validate this parameter is a string of characters consisting of upper- and lower-case alphanumeric characters with no spaces. You can also include underscores or any of the following characters: =,.@-
string
[REQUIRED]
The OAuth 2.0 access token or OpenID Connect ID token that is provided by the identity provider. Your application must get this token by authenticating the user who is using your application with a web identity provider before the application makes an AssumeRoleWithWebIdentity call. Timestamps in the token must be formatted as either an integer or a long integer. Tokens must be signed using either RSA keys (RS256, RS384, or RS512) or ECDSA keys (ES256, ES384, or ES512).
string
The fully qualified host component of the domain name of the OAuth 2.0 identity provider. Do not specify this value for an OpenID Connect identity provider.
Currently www.amazon.com and graph.facebook.com are the only supported identity providers for OAuth 2.0 access tokens. Do not include URL schemes and port numbers.
Do not specify this value for OpenID Connect ID tokens.
list
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 Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces in the Amazon Web Services General Reference.
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 resources in the account that owns the role. You cannot use session policies to grant more permissions than those allowed by the identity-based policy of the role that is being assumed. For more information, see Session Policies in the IAM User Guide.
(dict) --
A reference to the IAM managed policy that is passed as a session policy for a role session or a federated user session.
arn (string) --
The Amazon Resource Name (ARN) of the IAM managed policy to use as a session policy for the role. For more information about ARNs, see Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces in the Amazon Web Services General Reference.
string
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 resources in the account that owns the role. You cannot use session policies to grant more permissions than those allowed by the identity-based policy of the role that is being assumed. For more information, see Session Policies in the IAM User Guide.
The plaintext that you use for both inline and managed session policies can't exceed 2,048 characters. The JSON policy characters can be any ASCII character from the space character to the end of the valid character list (u0020 through u00FF). It can also include the tab (u0009), linefeed (u000A), and carriage return (u000D) characters.
For more information about role session permissions, see Session policies.
integer
The duration, in seconds, of the role session. The value can range from 900 seconds (15 minutes) up to the maximum session duration setting for the role. This setting can have a value from 1 hour to 12 hours. If you specify a value higher than this setting, the operation fails. For example, if you specify a session duration of 12 hours, but your administrator set the maximum session duration to 6 hours, your operation fails. To learn how to view the maximum value for your role, see View the Maximum Session Duration Setting for a Role in the IAM User Guide.
By default, the value is set to 3600 seconds.
integer
The minimum size, in bytes, of the session token that STS issues for the request. STS increases the session token to at least this size, regardless of its actual content. The value must not exceed 4,096 bytes. When set to 0 or not specified, the session token size is unchanged.
dict
Response Syntax
{
'Credentials': {
'AccessKeyId': 'string',
'SecretAccessKey': 'string',
'SessionToken': 'string',
'Expiration': datetime(2015, 1, 1)
},
'SubjectFromWebIdentityToken': 'string',
'AssumedRoleUser': {
'AssumedRoleId': 'string',
'Arn': 'string'
},
'PackedPolicySize': 123,
'Provider': 'string',
'Audience': 'string',
'SourceIdentity': 'string',
'SessionTokenUtilization': 123,
'SessionTokenSize': 123,
'TrustedIdentityPropagationContext': {
'OriginIdentity': {
'Subject': 'string',
'SubjectType': 'string',
'Issuer': 'string',
'FederatedProviderArn': 'string'
},
'TransactionContext': {
'IdentityProvider': {
'string': 'string'
}
}
}
}
Response Structure
(dict) --
Contains the response to a successful AssumeRoleWithWebIdentity request, including temporary Amazon Web Services credentials that can be used to make Amazon Web Services requests.
Credentials (dict) --
The temporary security credentials, which include an access key ID, a secret access key, and a security token.
AccessKeyId (string) --
The access key ID that identifies the temporary security credentials.
SecretAccessKey (string) --
The secret access key that can be used to sign requests.
SessionToken (string) --
The token that users must pass to the service API to use the temporary credentials.
Expiration (datetime) --
The date on which the current credentials expire.
SubjectFromWebIdentityToken (string) --
The unique user identifier that is returned by the identity provider. This identifier is associated with the WebIdentityToken that was submitted with the AssumeRoleWithWebIdentity call. The identifier is typically unique to the user and the application that acquired the WebIdentityToken (pairwise identifier). For OpenID Connect ID tokens, this field contains the value returned by the identity provider as the token's sub (Subject) claim.
AssumedRoleUser (dict) --
The Amazon Resource Name (ARN) and the assumed role ID, which are identifiers that you can use to refer to the resulting temporary security credentials. For example, you can reference these credentials as a principal in a resource-based policy by using the ARN or assumed role ID. The ARN and ID include the RoleSessionName that you specified when you called AssumeRole.
AssumedRoleId (string) --
A unique identifier that contains the role ID and the role session name of the role that is being assumed. The role ID is generated by Amazon Web Services when the role is created.
Arn (string) --
The ARN of the temporary security credentials that are returned from the AssumeRole action. For more information about ARNs and how to use them in policies, see IAM Identifiers in the IAM User Guide.
PackedPolicySize (integer) --
The percentage (0-100) of the maximum allowed session token size that the returned session token consumes.
This field is deprecated. Use SessionTokenUtilization instead.
Provider (string) --
The issuing authority of the web identity token presented. For OpenID Connect ID tokens, this contains the value of the iss field. For OAuth 2.0 access tokens, this contains the value of the ProviderId parameter that was passed in the AssumeRoleWithWebIdentity request.
Audience (string) --
The intended audience (also known as client ID) of the web identity token. This is traditionally the client identifier issued to the application that requested the web identity token.
SourceIdentity (string) --
The value of the source identity that is returned in the JSON web token (JWT) from the identity provider.
You can require users to set a source identity value when they assume a role. You do this by using the sts:SourceIdentity condition key in a role trust policy. That way, actions that are taken with the role are associated with that user. After the source identity is set, the value cannot be changed. It is present in the request for all actions that are taken by the role and persists across chained role sessions. You can configure your identity provider to use an attribute associated with your users, like user name or email, as the source identity when calling AssumeRoleWithWebIdentity. You do this by adding a claim to the JSON web token. To learn more about OIDC tokens and claims, see Using Tokens with User Pools in the Amazon Cognito Developer Guide. For more information about using source identity, see Monitor and control actions taken with assumed roles in the IAM User Guide.
The regex used to validate this parameter is a string of characters consisting of upper- and lower-case alphanumeric characters with no spaces. You can also include underscores or any of the following characters: =,.@-
SessionTokenUtilization (integer) --
The percentage (0-100) of the maximum allowed session token size that the returned session token consumes.
SessionTokenSize (integer) --
The size, in bytes, of the session token returned in the Credentials for this response.
TrustedIdentityPropagationContext (dict) --
The trusted identity propagation context that Amazon Web Services STS set in the session from the web identity token, through the context provider attached to the OpenID Connect identity provider. It is present only when Amazon Web Services STS set such context in the session. It contains the aws:OriginIdentity/Subject, aws:OriginIdentity/SubjectType, aws:OriginIdentity/Issuer and aws:OriginIdentity/FederatedProviderArn keys and the aws:TransactionContext/IdentityProvider/* keys that Amazon Web Services STS set in the session. Other keys in the session, such as aws:IdentityCenterInstanceArn and aws:IdentityStoreArn for an identity provider with an Identity Center instance attached, are not returned.
This element contains information about the end user. Do not log it.
OriginIdentity (dict) --
The identity of the end user on whose behalf the session acts.
Subject (string) --
The value of the aws:OriginIdentity/Subject key: the end user's identifier, taken from the token claim that the context provider maps as the subject.
SubjectType (string) --
The value of the aws:OriginIdentity/SubjectType key, which indicates whether the end user is a person ( user) or a non-human caller such as an application or service ( workload).
Issuer (string) --
The value of the aws:OriginIdentity/Issuer key. For AssumeRoleWithWebIdentity, this is the iss claim of the token without the https:// prefix. For AssumeRoleWithSAML, this is a hash of the key that signed the SAML assertion, not the Issuer element of the assertion.
FederatedProviderArn (string) --
The value of the aws:OriginIdentity/FederatedProviderArn key: the ARN of the IAM identity provider that the request federated through.
TransactionContext (dict) --
Additional claims about the request that the identity provider asserted.
IdentityProvider (dict) --
The session's aws:TransactionContext/IdentityProvider/* keys, keyed by the part of the key name after aws:TransactionContext/IdentityProvider/. Each value is up to 128 characters.
The number of entries is bounded twice. IAM limits how many keys a context provider maps when you configure it on the identity provider, and Amazon Web Services STS rejects a session whose session token exceeds the maximum size with PackedPolicyTooLarge.
(string) --
(string) --
{'Scope': 'string', 'SubjectMode': 'AWSIdentity | OriginIdentity'}
Returns a signed JSON Web Token (JWT) that represents the calling Amazon Web Services identity or, if you set SubjectMode to OriginIdentity, the human user or workload on whose behalf the calling session acts. The returned JWT can be used to authenticate with external services that support OIDC discovery. The token is signed by Amazon Web Services STS and can be publicly verified using the verification keys published at the issuer's JWKS endpoint.
The sub (subject) claim contains the identity that SubjectMode selects. Whichever subject mode you use, the principal_id claim under the https://sts.amazonaws.com/ namespace contains the ARN of the principal that requested the token, when that principal has an ARN. For a role session, this is the ARN of the role.
See also: AWS API Documentation
Request Syntax
client.get_web_identity_token(
Audience=[
'string',
],
DurationSeconds=123,
SigningAlgorithm='string',
Scope='string',
SubjectMode='AWSIdentity'|'OriginIdentity',
Tags=[
{
'Key': 'string',
'Value': 'string'
},
]
)
list
[REQUIRED]
The intended recipient of the web identity token. This value populates the aud claim in the JWT and should identify the service or application that will validate and use the token. The external service should verify this claim to ensure the token was intended for their use.
(string) --
integer
The duration, in seconds, for which the JSON Web Token (JWT) will remain valid. The value can range from 60 seconds (1 minute) to 3600 seconds (1 hour). If not specified, the default duration is 300 seconds (5 minutes). The token is designed to be short-lived and should be used for proof of identity, then exchanged for credentials or short-lived tokens in the external service.
string
[REQUIRED]
The cryptographic algorithm to use for signing the JSON Web Token (JWT). Valid values are RS256 (RSA with SHA-256) and ES384 (ECDSA using P-384 curve with SHA-384).
string
One or more OAuth 2.0 scope values to include in the JSON Web Token (JWT). Amazon Web Services STS copies the value exactly as you send it into the top-level scope claim of the token. If you don't specify Scope, the token doesn't include a scope claim.
Separate multiple values with a single space, as defined in RFC 6749, section 3.3 on the IETF website. Don't begin or end Scope with a space. Each scope value can contain printable ASCII characters except spaces, double quotation marks ( "), commas ( ,), and backslashes ( \).
You can't repeat a scope value. Scope values are case sensitive. This means that read and READ are separate values.
You can specify Scope only when SubjectMode is OriginIdentity and you request exactly one audience. To specify Scope, the calling principal must have permission for the sts:SetWebIdentityTokenScope action in addition to sts:GetWebIdentityToken. You can use the multivalued sts:IdentityTokenScope condition key in a policy to control which scope values a principal can request.
string
Specifies which identity STS puts in the sub (subject) claim of the JSON Web Token (JWT). Valid values are AWSIdentity and OriginIdentity. If you don't specify a value, Amazon Web Services STS uses AWSIdentity.
AWSIdentity – The sub claim contains the ARN of the calling Amazon Web Services principal.
OriginIdentity – The sub claim contains the value of the aws:OriginIdentity/Subject key in the trusted identity propagation context of the calling session. For example, this can identify the human user or workload on whose behalf the calling session acts. Amazon Web Services STS also adds a subject_mode claim to the token. To use OriginIdentity, the trusted identity propagation context of the calling session must contain the aws:OriginIdentity/Subject key and either the aws:OriginIdentity/Issuer key or the aws:OriginIdentity/FederatedProviderArn key. If it doesn't, or if the subject is blank, Amazon Web Services STS rejects the request with a validation error. Amazon Web Services STS denies the request if the subject begins with the text arn:, in any combination of uppercase and lowercase letters. Amazon Web Services STS also denies the request if the subject begins or ends with a space, or contains a control, format, or separator character other than a space.
You can use the sts:SubjectMode condition key in a policy to control which subject modes a principal can request.
list
An optional list of tags to include in the JSON Web Token (JWT). These tags are added as custom claims to the JWT and can be used by the downstream service for authorization decisions.
(dict) --
You can pass custom key-value pair attributes when you assume a role or federate a user. These are called session tags. You can then use the session tags to control access to resources. For more information, see Tagging Amazon Web Services STS Sessions in the IAM User Guide.
Key (string) -- [REQUIRED]
The key for a session tag.
You can pass up to 50 session tags. The plain text session tag keys can’t exceed 128 characters. For these and additional limits, see IAM and STS Character Limits in the IAM User Guide.
Value (string) -- [REQUIRED]
The value for a session tag.
You can pass up to 50 session tags. The plain text session tag values can’t exceed 256 characters. For these and additional limits, see IAM and STS Character Limits in the IAM User Guide.
dict
Response Syntax
{
'WebIdentityToken': 'string',
'Expiration': datetime(2015, 1, 1)
}
Response Structure
(dict) --
WebIdentityToken (string) --
A signed JSON Web Token (JWT) that represents the caller's Amazon Web Services identity or, if you set SubjectMode to OriginIdentity, the human user or workload on whose behalf the calling session acts. The token contains standard JWT claims such as subject, audience, expiration time, and additional identity attributes added by STS as custom claims. These can include the principal_id claim, which contains the ARN of the principal that requested the token, whichever subject mode you use. You can also add your own custom claims to the token by passing tags as request parameters to the GetWebIdentityToken API. The token is signed using the specified signing algorithm and can be verified using the verification keys available at the issuer's JWKS endpoint.
Expiration (datetime) --
The date and time when the web identity token expires, in UTC. The expiration is determined by adding the DurationSeconds value to the time the token was issued. After this time, the token should no longer be considered valid.