There are more AWS SDK examples available in the AWS Doc SDK Examples
Use DeleteRolePolicy
with an AWS SDK or CLI
The following code examples show how to use DeleteRolePolicy
.
- .NET
-
- AWS SDK for .NET
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. /// <summary> /// Delete an IAM role policy. /// </summary> /// <param name="roleName">The name of the IAM role.</param> /// <param name="policyName">The name of the IAM role policy to delete.</param> /// <returns>A Boolean value indicating the success of the action.</returns> public async Task<bool> DeleteRolePolicyAsync(string roleName, string policyName) { var response = await _IAMService.DeleteRolePolicyAsync(new DeleteRolePolicyRequest { PolicyName = policyName, RoleName = roleName, }); return response.HttpStatusCode == System.Net.HttpStatusCode.OK; }
-
For API details, see DeleteRolePolicy in AWS SDK for .NET API Reference.
-
- CLI
-
- AWS CLI
-
To remove a policy from an IAM role
The following
delete-role-policy
command removes the policy namedExamplePolicy
from the role namedTest-Role
.aws iam delete-role-policy \ --role-name
Test-Role
\ --policy-nameExamplePolicy
This command produces no output.
For more information, see Modifying a role in the AWS IAM User Guide.
-
For API details, see DeleteRolePolicy
in AWS CLI Command Reference.
-
- JavaScript
-
- SDK for JavaScript (v3)
-
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. import { DeleteRolePolicyCommand, IAMClient } from "@aws-sdk/client-iam"; const client = new IAMClient({}); /** * * @param {string} roleName * @param {string} policyName */ export const deleteRolePolicy = (roleName, policyName) => { const command = new DeleteRolePolicyCommand({ RoleName: roleName, PolicyName: policyName, }); return client.send(command); };
-
For API details, see DeleteRolePolicy in AWS SDK for JavaScript API Reference.
-
- PowerShell
-
- Tools for PowerShell
-
Example 1: This example deletes the inline policy
S3AccessPolicy
that is embedded in the IAM roleS3BackupRole
.Remove-IAMRolePolicy -PolicyName S3AccessPolicy -RoleName S3BackupRole
-
For API details, see DeleteRolePolicy in AWS Tools for PowerShell Cmdlet Reference.
-