aws ec2 associate-iam-instance-profile
Associates an IAM instance profile with a running or stopped instance. AWS CLI reference
1 example 2 options Its page in the AWS CLI reference
Examples
To associate an IAM instance profile with an instance
The following associate-iam-instance-profile example associates an IAM instance profile named admin-role with instance i-123456789abcde123.
aws ec2 associate-iam-instance-profile --instance-id i-123456789abcde123 --iam-instance-profile Name=admin-roleIdentify--instance-idThe ID of the instance.--iam-instance-profileThe IAM instance profile.Its output
{
"IamInstanceProfileAssociation": {
"InstanceId": "i-123456789abcde123",
"State": "associating",
"AssociationId": "iip-assoc-0e7736511a163c209",
"IamInstanceProfile": {
"Id": "AIPAJBLK7RKJKWDXVHIEC",
"Arn": "arn:aws:iam::123456789012:instance-profile/admin-role"
}
}
}For more information, see Attach an IAM role to an instance in the Amazon EC2 User Guide.
Options
--iam-instance-profileThe IAM instance profile.--instance-idThe ID of the instance.