Use UpdateAssumeRolePolicy with a CLI
The following code examples show how to use UpdateAssumeRolePolicy.
- CLI
-
- Amazon CLI
-
To update the trust policy for an IAM role
The following
update-assume-role-policyexample updates the trust policy for the role namedTest-Role.aws iam update-assume-role-policy \ --role-nameTest-Role\ --policy-documentfile://Test-Role-Trust-Policy.jsonContents of
Test-Role-Trust-Policy.json:{ "Version":"2012-10-17", "Statement": [ { "Sid": "Statement1", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:root" }, "Action": "sts:AssumeRole" } ] }This command produces no output.
The trust policy is defined as a JSON document in the Test-Role-Trust-Policy.json file. (The file name and extension do not have significance.) The trust policy must specify a principal.
To update the permissions policy for a role, use the
put-role-policycommand.For more information, see Creating IAM roles
in the Amazon IAM User Guide. -
For API details, see UpdateAssumeRolePolicy
in Amazon CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: This example updates the IAM role named
ClientRolewith a new trust policy, the contents of which come from the fileClientRolePolicy.json. Note that you must use the-Rawswitch parameter to successfully process the contents of the JSON file.Update-IAMAssumeRolePolicy -RoleName ClientRole -PolicyDocument (Get-Content -raw ClientRolePolicy.json)-
For API details, see UpdateAssumeRolePolicy
in Amazon Tools for PowerShell Cmdlet Reference (V4).
-
- Tools for PowerShell V5
-
Example 1: This example updates the IAM role named
ClientRolewith a new trust policy, the contents of which come from the fileClientRolePolicy.json. Note that you must use the-Rawswitch parameter to successfully process the contents of the JSON file.Update-IAMAssumeRolePolicy -RoleName ClientRole -PolicyDocument (Get-Content -raw ClientRolePolicy.json)-
For API details, see UpdateAssumeRolePolicy
in Amazon Tools for PowerShell Cmdlet Reference (V5).
-
For a complete list of Amazon SDK developer guides and code examples, see Using this service with an Amazon SDK. This topic also includes information about getting started and details about previous SDK versions.