Which solution will ensure that an instance profile is attached to all existing and future EC2 instances in the Region?
Configure an Amazon EventBridge (Amazon CloudWatch Events) rule that reacts to EC2 RunInstances API calls. Configure the rule to invoke an AWS Lambda function to attach the default instance profile to the EC2 instances.
Configure the ec2-instance-profile-attached AWS Config managed rule with a trigger type of configuration changes. Configure an automatic remediation action that invokes an AWS Systems Manager Automation runbook to attach the default instance profile to the EC2 instances.
Configure an Amazon EventBridge (Amazon CloudWatch Events) rule that reacts to EC2 Startlnstances API calls. Configure the rule to invoke an AWS Systems Manager Automation runbook to attach the default instance profile to the EC2 instances.
Configure the iam-role-managed-policy-check AWS Config managed rule with a trigger type of configuration changes. Configure an automatic remediation action that invokes an AWS Lambda function to attach the default instance profile to the EC2 instances.
Explanations:
An EventBridge rule that reacts to EC2 RunInstances API calls would not be suitable for attaching a profile to existing instances that were already launched. This would only apply to new instances being launched after the rule is configured.
Theec2-instance-profile-attachedAWS Config rule with automatic remediation can ensure all instances have an instance profile attached. It monitors EC2 instances’ configurations, and if any EC2 instance is missing an instance profile, it triggers an automation action to attach the default profile.
An EventBridge rule reacting to EC2 StartInstances API calls would not address the issue for instances that are already running without a profile, as it would only apply when instances are started after being stopped.
Theiam-role-managed-policy-checkAWS Config rule monitors IAM policies attached to roles, but it would not help in automatically attaching a profile to EC2 instances that are missing one. The rule doesn’t focus on EC2 instance profiles.