create-role¶
Creates a new role for your AWS account. For more information about roles, go to IAM 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.
Refer to AWS help for descriptions of global parameters.
Synopsis¶
create-role
[--path <value>]
--role-name <value>
--assume-role-policy-document <value>
[--max-session-duration <value>]
Options¶
--description (string)
A description of the role.
Length constraints: Maximum length 1000
Pattern: [\u0009\u000A\u000D\u0020-\u007E\u00A1-\u00FF]*
Required: No
--path (string)
The path to the role. For more information about paths, refer to the AWS IAM Identifiers documentation.
This parameter is optional. If it is not included, it defaults to a slash (/).
This parameter allows (through its regex pattern) a string of characters consisting of either a forward slash (/) by itself or a string that must begin and end with forward slashes. In addition, it can contain any ASCII character from the “!” (u0021) through the DEL character (u007F), including most punctuation characters, digits, and upper and lowercased letters.
--role-name (string)
The name of the role to create.
IAM user, group, role, and policy names must be unique within the account. Names are not distinguished by case. For example, you cannot create resources named both “MyResource” and “myresource”.
--assume-role-policy-document (string)
The trust relationship policy document that grants an entity permission to assume the role.
In IAM, you must provide a JSON policy that has been converted to a string. However, for AWS CloudFormation templates formatted in YAML, you can provide the policy in JSON or YAML format. AWS CloudFormation always converts a YAML policy to JSON format before submitting it to IAM.
The regex pattern used to validate this parameter is a string of characters consisting of the following:
Any printable ASCII character ranging from the space character (u0020) through the end of the ASCII character range
The printable characters in the Basic Latin and Latin-1 Supplement character set (through u00FF)
The special characters tab (u0009), line feed (u000A), and carriage return (u000D)
Upon success, the response includes the same trust policy as a URL-encoded JSON string.
--max-session-duration (integer)
The maximum session duration (in seconds) that you want to set for the specified role. If you do not specify a value for this setting, the default maximum of one hour is applied. This setting can have a value from 1 hour to 12 hours.
Anyone who assumes the role from the AWS CLI or API can use the
DurationSecondsAPI parameter or theduration-secondsCLI parameter to request a longer session. TheMaxSessionDurationsetting determines the maximum duration that can be requested using theDurationSecondsparameter. If users don’t specify a value for theDurationSecondsparameter, their security credentials are valid for one hour by default. This applies when you use theAssumeRole*API operations or theassume-role*CLI operations but does not apply when you use those operations to create a console URL. For more information, refer to Using IAM Roles in the IAM User Guide.
Refer to AWS help for descriptions of global parameters.
Examples¶
To create an IAM role
The following create-role command creates a role named Test-Role and
attaches a trust policy to it
aws iam create-role --role-name Test-Role --assume-role-policy-document file://Test-Role-Trust-Policy.json
Output example:
{
"Role": {
"AssumeRolePolicyDocument": "<URL-encoded-JSON>",
"RoleId": "AKIAIOSFODNN7EXAMPLE",
"CreateDate": "2013-06-07T20:43:32.821Z",
"RoleName": "Test-Role",
"Path": "/",
"Arn": "arn:aws:iam::123456789012:role/Test-Role"
}
}
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 attach a permissions policy to a role, use the put-role-policy command.
For more information, refer to Creating a Role in the Using IAM guide.
Output¶
Role -> (structure)
A structure containing details about the new role.
Description -> (string)
A description of the role.
Path -> (string)
The path to the role. For more information about paths, refer to the AWS IAM Identifiers documentation.
RoleName -> (string)
The friendly name that identifies the role.
RoleId -> (string)
The stable and unique string identifying the role. For more information about IDs, refer to the AWS IAM Identifiers documentation.
Arn -> (string)
The Amazon Resource Name (ARN) specifying the role. For more information about ARNs and how to use them in policies, refer to the AWS IAM Identifiers documentation.
CreateDate -> (timestamp)
The date and time, in ISO 8601 date-time format, when the role was created.
AssumeRolePolicyDocument -> (string)
The policy that grants an entity permission to assume the role.
MaxSessionDuration -> (integer)
The maximum session duration (in seconds) for the specified role. Anyone who uses the AWS CLI, or API to assume the role can specify the duration using the optional
DurationSecondsAPI parameter orduration-secondsCLI parameter.

