How to attach instance profile on EC2 with AWS CLI

This is a quick note to remind me on how to attach or associate an instance profile (IAM role) to an EC2 instance using AWS CLI. There is a bonus section at the end to show how to replace one IAM role with another one directly. In this example, I already have a running EC2 instance i-0357ecc1111111111 running. I want to attach a new instance profile called SSMInstanceProfile to this instance....

March 5, 2024 · 3 min · 436 words · kenno