Package
@aws-sdk/client-sts
Installation
Creating the client
us-east-1 as a reliable default.
Commands
GetCallerIdentityCommand — who am I?
GetCallerIdentityCommand — who am I?
Returns the AWS account ID, IAM ARN, and user/role ID for the caller’s credentials. Requires no input parameters and works regardless of IAM permissions — any authenticated caller can invoke it.This is commonly used in CI/CD pipelines to verify which credentials are active, and in Lambda handlers to log the execution context (see the working with Lambda page for a full example).
AssumeRoleCommand — get temporary credentials for a role
AssumeRoleCommand — get temporary credentials for a role
Returns short-lived credentials scoped to the assumed role. Use these when your code needs to act as a different IAM role, cross-account access, or service-to-service delegation.
AssumeRoleWithWebIdentityCommand — OIDC federation
AssumeRoleWithWebIdentityCommand — OIDC federation
Exchange an OIDC token (e.g., from a Kubernetes service account, GitHub Actions, or Cognito) for temporary AWS credentials.
GetSessionTokenCommand — temporary credentials with MFA
GetSessionTokenCommand — temporary credentials with MFA
Returns temporary credentials for the current IAM user. Primarily used to generate credentials that satisfy MFA-required API calls.
Using assumed-role credentials in another client
After callingAssumeRoleCommand, pass the returned credentials directly into another SDK client:
Credential chaining with fromTemporaryCredentials
Use thefromTemporaryCredentials helper from @aws-sdk/credential-providers to automatically refresh assumed-role credentials before they expire:
fromTemporaryCredentials handles credential refresh transparently, so long-running processes do not need to manually call AssumeRoleCommand again.