Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

Use GetRolePolicy with a CLI

Focus mode
Use GetRolePolicy with a CLI - AWS Identity and Access Management

The following code examples show how to use GetRolePolicy.

CLI
AWS CLI

To get information about a policy attached to an IAM role

The following get-role-policy command gets information about the specified policy attached to the role named Test-Role.

aws iam get-role-policy \ --role-name Test-Role \ --policy-name ExamplePolicy

Output:

{ "RoleName": "Test-Role", "PolicyDocument": { "Statement": [ { "Action": [ "s3:ListBucket", "s3:Put*", "s3:Get*", "s3:*MultipartUpload*" ], "Resource": "*", "Effect": "Allow", "Sid": "1" } ] } "PolicyName": "ExamplePolicy" }

For more information, see Creating IAM roles in the AWS IAM User Guide.

  • For API details, see GetRolePolicy in AWS CLI Command Reference.

PowerShell
Tools for PowerShell

Example 1: This example returns the permissions policy document for the policy named oneClick_lambda_exec_role_policy that is embedded in the IAM role lamda_exec_role. The resulting policy document is URL encoded. It is decoded in this example with the UrlDecode .NET method.

$results = Get-IAMRolePolicy -RoleName lambda_exec_role -PolicyName oneClick_lambda_exec_role_policy $results

Output:

PolicyDocument PolicyName UserName -------------- ---------- -------- %7B%0A%20%20%22Version%22%3A%20%222012-10-17%22%2C%... oneClick_lambda_exec_role_policy lambda_exec_role
[System.Reflection.Assembly]::LoadWithPartialName("System.Web.HttpUtility") [System.Web.HttpUtility]::UrlDecode($results.PolicyDocument)

Output:

{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "logs:*" ], "Resource": "arn:aws:logs:*:*:*" }, { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:PutObject" ], "Resource": [ "arn:aws:s3:::*" ] } ] }
  • For API details, see GetRolePolicy in AWS Tools for PowerShell Cmdlet Reference.

AWS CLI

To get information about a policy attached to an IAM role

The following get-role-policy command gets information about the specified policy attached to the role named Test-Role.

aws iam get-role-policy \ --role-name Test-Role \ --policy-name ExamplePolicy

Output:

{ "RoleName": "Test-Role", "PolicyDocument": { "Statement": [ { "Action": [ "s3:ListBucket", "s3:Put*", "s3:Get*", "s3:*MultipartUpload*" ], "Resource": "*", "Effect": "Allow", "Sid": "1" } ] } "PolicyName": "ExamplePolicy" }

For more information, see Creating IAM roles in the AWS IAM User Guide.

  • For API details, see GetRolePolicy in AWS CLI Command Reference.

For a complete list of AWS SDK developer guides and code examples, see Using this service with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.