AWS Security ChangesHomeSearch

AWS code-library documentation change

Service: code-library · 2025-06-28 · Documentation low

File: code-library/latest/ug/iam_example_iam_CreateRole_section.md

Summary

Added PowerShell V5 example for role creation with trust policy

Security assessment

Documents secure role creation with assume-role policy. Important for least privilege but not addressing a specific vulnerability.

Diff

diff --git a/code-library/latest/ug/iam_example_iam_CreateRole_section.md b/code-library/latest/ug/iam_example_iam_CreateRole_section.md
index bcd5fbf03..84b86800a 100644
--- a//code-library/latest/ug/iam_example_iam_CreateRole_section.md
+++ b//code-library/latest/ug/iam_example_iam_CreateRole_section.md
@@ -645,0 +646,47 @@ PowerShell
+**Tools for PowerShell V5**
+    
+
+**Example 1: This example creates a new role named`MyNewRole` and attaches to it the policy found in the file `NewRoleTrustPolicy.json`. Note that you must use the `-Raw` switch parameter to successfully process the JSON policy file. The policy document displayed in the output is URL encoded. It is decoded in this example with the `UrlDecode` .NET method. **
+    
+    
+    $results = New-IAMRole -AssumeRolePolicyDocument (Get-Content -raw NewRoleTrustPolicy.json) -RoleName MyNewRole
+    $results
+    
+
+**Output:**
+    
+    
+    Arn                      : arn:aws:iam::123456789012:role/MyNewRole
+    AssumeRolePolicyDocument : %7B%0D%0A%20%20%22Version%22%3A%20%222012-10-17%22%2C%0D%0A%20%20%22Statement%22
+                               %3A%20%5B%0D%0A%20%20%20%20%7B%0D%0A%20%20%20%20%20%20%22Sid%22%3A%20%22%22%2C
+                               %0D%0A%20%20%20%20%20%20%22Effect%22%3A%20%22Allow%22%2C%0D%0A%20%20%20%20%20%20
+                               %22Principal%22%3A%20%7B%0D%0A%20%20%20%20%20%20%20%20%22AWS%22%3A%20%22arn%3Aaws
+                               %3Aiam%3A%3A123456789012%3ADavid%22%0D%0A%20%20%20%20%20%20%7D%2C%0D%0A%20%20%20
+                               %20%20%20%22Action%22%3A%20%22sts%3AAssumeRole%22%0D%0A%20%20%20%20%7D%0D%0A%20
+                               %20%5D%0D%0A%7D
+    CreateDate               : 4/15/2015 11:04:23 AM
+    Path                     : /
+    RoleId                   : V5PAJI2KPN4EAEXAMPLE1
+    RoleName                 : MyNewRole
+    
+    [System.Reflection.Assembly]::LoadWithPartialName("System.Web.HttpUtility")
+    [System.Web.HttpUtility]::UrlDecode($results.AssumeRolePolicyDocument)
+    {
+      "Version": "2012-10-17",
+      "Statement": [
+        {
+          "Sid": "",
+          "Effect": "Allow",
+          "Principal": {
+            "AWS": "arn:aws:iam::123456789012:David"
+          },
+          "Action": "sts:AssumeRole"
+        }
+      ]
+    }
+
+  * For API details, see [CreateRole](https://docs.aws.amazon.com/powershell/v5/reference) in _AWS Tools for PowerShell Cmdlet Reference (V5)_. 
+
+
+
+