In my AWS account I have an IAM role with a single policy attached: AdministratorAccess
The IAM role’s trust relationship looks like this:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": [
"arn:aws:iam::<account-id-1>:root",
"arn:aws:iam::<account-id-2>:root",
"arn:aws:iam::<account-id-3>:root",
"arn:aws:iam::<account-id-4>:root"
],
"Service": "ec2.amazonaws.com"
},
"Action": "sts:AssumeRole",
"Condition": {}
}
]
}
When I attempt create a new EC2 instance, I want to attach the IAM role to it but the IAM role does not appear in the the list of the roles that I choose from.
What am I doing wrong?
Tried to have my trust policy without the AWS principal but this didn’t work wither.
Couldn’t find an answer or a prev question about it.
2
Answers
The Trust Policy should grant permission to the EC2 Service to assume the role, such as:
If confused, you can create an IAM Role in the IAM management console to see the default Trust Policy that it creates. Make sure you select EC2 as the Service when creating the role.
What you actually need is Instance profile
I’m guessing you created the role via CLI, so you need to create instance profile to attach to EC2. (Example use same name for role and profile)
Then add the role to instance profile
Then try selecting it at EC2 creation.
AWS Docs – Instance profile for EC2