How would you use the AWS CLI to manage IAM roles and policies? Can you provide an example of a command that creates or modifies a role or policy?
Using the AWS CLI, I can create IAM roles with create-role, define trust relationships through an assume-role policy, create custom policies using create-policy, and attach policies to roles using attach-role-policy. To modify a policy, I create a new policy version using create-policy-version and set it as the default. For updating who can assume a role, I use update-assume-role-policy.
Example:
aws iam create-role \
--role-name EC2-S3-Access-Role \
--assume-role-policy-document file://trust-policy.json
This creates an IAM role that can later be assigned permissions through managed or custom policies.