A SysOps administrator is configuring a Python script to automate the remediation of non-compliant Amazon EC2 instances. The script associates an IAM instance profile containing the IAM role `AppLoggingRole` with EC2 instances that currently lack one.
The administrator's IAM user has the following IAM policy attached:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeInstances",
"ec2:AssociateIamInstanceProfile",
"ec2:ReplaceIamInstanceProfileAssociation"
],
"Resource": "*"
}
]
}
When running the script, the `ec2:AssociateIamInstanceProfile` API call fails with an `AccessDenied` error.
Which of the following is the root cause of this error?
- The administrator's IAM user lacks the iam:PassRole permission to pass the AppLoggingRole role to the Amazon EC2 service.Answer
- BThe trust policy of the AppLoggingRole role does not allow the administrator's IAM user to perform the sts:AssumeRole action.
- CThe Amazon EC2 service principal (ec2.amazonaws.com) is not listed in the trust relationship of the AppLoggingRole role.
- DThe administrator's IAM policy must include the sts:AssumeRole permission for the AppLoggingRole role instead of EC2 actions.
Answer
The administrator's IAM user lacks the iam:PassRole permission to pass the AppLoggingRole role to the Amazon EC2 service.
To associate an IAM instance profile with an EC2 instance, the SysOps administrator's IAM user must have the iam:PassRole permission. This permission allows the user to pass the specified role to the Amazon EC2 service. Without it, the ec2:AssociateIamInstanceProfile API call returns an AccessDenied error.
Step-by-Step Solution
Key Concept
IAM PassRole Permission for Service Delegation
Estimated Time:2m 0s