GetRoleCommand

Retrieves information about the specified role, including the role's path, GUID, ARN, and the role's trust policy that grants permission to assume the role. For more information about roles, see IAM roles  in the IAM User Guide.

Policies returned by this operation are URL-encoded compliant with RFC 3986 . You can use a URL decoding method to convert the policy back to plain JSON text. For example, if you use Java, you can use the decode method of the java.net.URLDecoder utility class in the Java SDK. Other languages and SDKs provide similar functionality.

Example Syntax

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

import { IAMClient, GetRoleCommand } from "@aws-sdk/client-iam"; // ES Modules import
// const { IAMClient, GetRoleCommand } = require("@aws-sdk/client-iam"); // CommonJS import
const client = new IAMClient(config);
const input = { // GetRoleRequest
  RoleName: "STRING_VALUE", // required
};
const command = new GetRoleCommand(input);
const response = await client.send(command);
// { // GetRoleResponse
//   Role: { // Role
//     Path: "STRING_VALUE", // required
//     RoleName: "STRING_VALUE", // required
//     RoleId: "STRING_VALUE", // required
//     Arn: "STRING_VALUE", // required
//     CreateDate: new Date("TIMESTAMP"), // required
//     AssumeRolePolicyDocument: "STRING_VALUE",
//     Description: "STRING_VALUE",
//     MaxSessionDuration: Number("int"),
//     PermissionsBoundary: { // AttachedPermissionsBoundary
//       PermissionsBoundaryType: "PermissionsBoundaryPolicy",
//       PermissionsBoundaryArn: "STRING_VALUE",
//     },
//     Tags: [ // tagListType
//       { // Tag
//         Key: "STRING_VALUE", // required
//         Value: "STRING_VALUE", // required
//       },
//     ],
//     RoleLastUsed: { // RoleLastUsed
//       LastUsedDate: new Date("TIMESTAMP"),
//       Region: "STRING_VALUE",
//     },
//   },
// };

Example Usage

 Loading code editorLoading code editor

GetRoleCommand Input

See GetRoleCommandInput for more details

Parameter
Type
Description
RoleName
Required
string | undefined

The name of the IAM role to get information about.

This parameter allows (through its regex pattern ) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.-

GetRoleCommand Output

See GetRoleCommandOutput for details

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
Role
Required
Role | undefined

A structure containing details about the IAM role.

Throws

Name
Fault
Details
NoSuchEntityException
client

The request was rejected because it referenced a resource entity that does not exist. The error message describes the resource.

ServiceFailureException
server

The request processing has failed because of an unknown error, exception or failure.

IAMServiceException
Base exception class for all service exceptions from IAM service.