Services or capabilities described in AWS documentation might vary by Region. To see the differences applicable to the AWS European Sovereign Cloud Region, see the AWS European Sovereign Cloud User Guide.Use DeleteRolePolicy with an AWS SDK or CLI
The following code examples show how to use DeleteRolePolicy.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in
context in the following code examples:
- .NET
-
- SDK for .NET
-
/// <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;
}
- CLI
-
- AWS CLI
-
To remove a policy from an IAM role
The following delete-role-policy command removes the policy named ExamplePolicy from the role named Test-Role.
aws iam delete-role-policy \
--role-name Test-Role \
--policy-name ExamplePolicy
This command produces no output.
For more information, see Modifying a role in the AWS IAM User Guide.
- JavaScript
-
- SDK for JavaScript (v3)
-
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);
};
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: This example deletes the inline policy S3AccessPolicy that is embedded in the IAM role S3BackupRole.
Remove-IAMRolePolicy -PolicyName S3AccessPolicy -RoleName S3BackupRole
- Tools for PowerShell V5
-
Example 1: This example deletes the inline policy S3AccessPolicy that is embedded in the IAM role S3BackupRole.
Remove-IAMRolePolicy -PolicyName S3AccessPolicy -RoleName S3BackupRole
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.