Options
All
  • Public
  • Public/Protected
  • All
Menu

Class GetCallerIdentityCommand

Returns details about the IAM user or role whose credentials are used to call the operation.

No permissions are required to perform this operation. If an administrator adds a policy to your IAM user or role that explicitly denies access to the sts:GetCallerIdentity action, you can still perform this operation. Permissions are not required because the same information is returned when an IAM user or role is denied access. To view an example response, see I Am Not Authorized to Perform: iam:DeleteVirtualMFADevice in the IAM User Guide.

example

Use a bare-bones client and the command you need to make an API call.

import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts"; // ES Modules import
// const { STSClient, GetCallerIdentityCommand } = require("@aws-sdk/client-sts"); // CommonJS import
const client = new STSClient(config);
const command = new GetCallerIdentityCommand(input);
const response = await client.send(command);
see

GetCallerIdentityCommandInput for command's input shape.

see

GetCallerIdentityCommandOutput for command's response shape.

see

config for STSClient's config shape.

example

To get details about a calling IAM user

// This example shows a request and response made with the credentials for a user named Alice in the AWS account 123456789012.
const input = {};
const command = new GetCallerIdentityCommand(input);
const response = await client.send(command);
/* response ==
{
  "Account": "123456789012",
  "Arn": "arn:aws:iam::123456789012:user/Alice",
  "UserId": "AKIAI44QH8DHBEXAMPLE"
}
*\/
// example id: to-get-details-about-a-calling-iam-user-1480540050376
example

To get details about a calling user federated with AssumeRole

// This example shows a request and response made with temporary credentials created by AssumeRole. The name of the assumed role is my-role-name, and the RoleSessionName is set to my-role-session-name.
const input = {};
const command = new GetCallerIdentityCommand(input);
const response = await client.send(command);
/* response ==
{
  "Account": "123456789012",
  "Arn": "arn:aws:sts::123456789012:assumed-role/my-role-name/my-role-session-name",
  "UserId": "AKIAI44QH8DHBEXAMPLE:my-role-session-name"
}
*\/
// example id: to-get-details-about-a-calling-user-federated-with-assumerole-1480540158545
example

To get details about a calling user federated with GetFederationToken

// This example shows a request and response made with temporary credentials created by using GetFederationToken. The Name parameter is set to my-federated-user-name.
const input = {};
const command = new GetCallerIdentityCommand(input);
const response = await client.send(command);
/* response ==
{
  "Account": "123456789012",
  "Arn": "arn:aws:sts::123456789012:federated-user/my-federated-user-name",
  "UserId": "123456789012:my-federated-user-name"
}
*\/
// example id: to-get-details-about-a-calling-user-federated-with-getfederationtoken-1480540231316

Hierarchy

Implements

Index

Constructors

constructor

Properties

Readonly input

Readonly middlewareStack

Methods

Static getEndpointParameterInstructions