You can create an IAM Role using the AWS CLI by defining the trust policy JSON file and using the create-role command.
Example Code:
aws iam create-role --role-name ExampleRole --assume-role-policy-document file://trust-policy.json
The trust-policy.json might look like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}