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

CreateRole() public method

Creates a new role for your AWS account. For more information about roles, go to Working with Roles. For information about limitations on role names and the number of roles you can create, go to Limitations on IAM Entities in the IAM User Guide.
/// The request was rejected because it attempted to create a resource that already exists. /// /// 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 the policy document was malformed. The error message /// describes the specific error. /// /// The request processing has failed because of an unknown error, exception or failure. ///
public CreateRole ( CreateRoleRequest request ) : CreateRoleResponse
request Amazon.IdentityManagement.Model.CreateRoleRequest Container for the necessary parameters to execute the CreateRole service method.
return Amazon.IdentityManagement.Model.CreateRoleResponse
        public CreateRoleResponse CreateRole(CreateRoleRequest request)
        {
            var marshaller = new CreateRoleRequestMarshaller();
            var unmarshaller = CreateRoleResponseUnmarshaller.Instance;

            return Invoke<CreateRoleRequest,CreateRoleResponse>(request, marshaller, unmarshaller);
        }

Usage Example

        public virtual string PrepMode_CreateRole(AmazonIdentityManagementServiceClient iamClient, string roleName,
            string policyText, string trustRelationshipText)
        {
            var roleArn = String.Empty;

            // Use the CreateRoleRequest object to define the role. The AssumeRolePolicyDocument property should be
            // set to the value of the trustRelationshipText parameter.

            var createRoleRequest = new CreateRoleRequest
            {
                AssumeRolePolicyDocument = trustRelationshipText,
                RoleName = roleName
            };
            roleArn = iamClient.CreateRole(createRoleRequest).Role.Arn;

            // Use the PutRolePolicyRequest object to define the request. Select whatever policy name you would like.
            // The PolicyDocument property is there the policy is described.
            var putRolePolicyRequest = new PutRolePolicyRequest
            {
                RoleName = roleName,
                PolicyName = String.Format("{0}_policy", roleName),
                PolicyDocument = policyText
            };
            iamClient.PutRolePolicy(putRolePolicyRequest);

            return roleArn;
        }
All Usage Examples Of Amazon.IdentityManagement.AmazonIdentityManagementServiceClient::CreateRole
AmazonIdentityManagementServiceClient