There are more AWS SDK examples available in the AWS Doc SDK Examples
Use GetRolePolicy
with a CLI
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 namedTest-Role
.aws iam get-role-policy \ --role-name
Test-Role
\ --policy-nameExamplePolicy
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 rolelamda_exec_role
. The resulting policy document is URL encoded. It is decoded in this example with theUrlDecode
.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.
-