Amazon.IdentityManagement.AmazonIdentityManagementServiceClient.DeleteRolePolicy C# (CSharp) Method

DeleteRolePolicy() public method

Deletes the specified inline policy that is embedded in the specified IAM role.

A role can also have managed policies attached to it. To detach a managed policy from a role, use DetachRolePolicy. For more information about policies, refer to Managed Policies and Inline Policies in the IAM User Guide.

/// The request was rejected because it attempted to create resources beyond the current /// AWS account limits. The error message describes the limit exceeded. /// /// The request was rejected because it referenced an entity that does not exist. The /// error message describes the entity. /// /// The request processing has failed because of an unknown error, exception or failure. ///
public DeleteRolePolicy ( DeleteRolePolicyRequest request ) : Amazon.IdentityManagement.Model.DeleteRolePolicyResponse
request Amazon.IdentityManagement.Model.DeleteRolePolicyRequest Container for the necessary parameters to execute the DeleteRolePolicy service method.
return Amazon.IdentityManagement.Model.DeleteRolePolicyResponse
        public DeleteRolePolicyResponse DeleteRolePolicy(DeleteRolePolicyRequest request)
        {
            var marshaller = new DeleteRolePolicyRequestMarshaller();
            var unmarshaller = DeleteRolePolicyResponseUnmarshaller.Instance;

            return Invoke<DeleteRolePolicyRequest,DeleteRolePolicyResponse>(request, marshaller, unmarshaller);
        }

Usage Example

        public virtual void PrepMode_RemoveRoles(AmazonIdentityManagementServiceClient iamClient, params string[] roles)
        {
            foreach (var roleName in roles)
            {
                try
                {
                    iamClient.GetRole(new GetRoleRequest {RoleName = roleName});
                    Console.WriteLine("Removing old role {0}.", roleName);
                    // Remove existing policies
                    var listRolePoliciesResponse =
                        iamClient.ListRolePolicies(new ListRolePoliciesRequest {RoleName = roleName});
                    foreach (var policyName in listRolePoliciesResponse.PolicyNames)
                    {
                        var deleteRolePolicyRequest = new DeleteRolePolicyRequest
                        {
                            PolicyName = policyName,
                            RoleName = roleName
                        };
                        iamClient.DeleteRolePolicy(deleteRolePolicyRequest);
                    }
                    iamClient.DeleteRole(new DeleteRoleRequest {RoleName = roleName});
                }
                catch (NoSuchEntityException)
                {

                    // Role doesn't exist, so don't do anything.
                    // Gobble the exception and loop.
                    break;
                }
            }
        }
All Usage Examples Of Amazon.IdentityManagement.AmazonIdentityManagementServiceClient::DeleteRolePolicy
AmazonIdentityManagementServiceClient