# AWS EC2 instance create via Ansible IAM Roles instance\_profile\_name UnauthorizedOperation: Error

**URL:** <https://forum.ansible.com/t/aws-ec2-instance-create-via-ansible-iam-roles-instance-profile-name-unauthorizedoperation-error/15542>\
**Category:** Ansible Project\
**Tags:** aws\
**Created:** [June 25, 2014, 6:42am UTC](https://forum.ansible.com/t/aws-ec2-instance-create-via-ansible-iam-roles-instance-profile-name-unauthorizedoperation-error/15542 "2014-06-25T06:42:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Faisal\_Ali\_Rabbani](https://avatars.discourse-cdn.com/v4/letter/f/278dde/32.png) [@Faisal\_Ali\_Rabbani](https://forum.ansible.com/u/Faisal_Ali_Rabbani)\
**Post date:** [June 25, 2014, 6:42am UTC](https://forum.ansible.com/t/aws-ec2-instance-create-via-ansible-iam-roles-instance-profile-name-unauthorizedoperation-error/15542/1 "2014-06-25T06:42:25Z")

</div>

I am trying to create EC2 instance via ansible using IAM roles but I while launching new instance I get error

```auto
failed: [localhost] => (item= IAMRole-1) => {"failed": true, "item": " IAMRole-1"}
msg: Instance creation failed => UnauthorizedOperation: You are not authorized to perform
this operation. Encoded authorization failure message: Ckcjt2GD81D5dlF6XakTSDypnwrgeQb0k
ouRMKh3Ol1jue553EZ7OXPt6fk1Q1-4HM-tLNPCkiX7ZgJWXYGSjHg2xP1A9LR7KBiXYeCtFKEQIC
W9cot3KAKPVcNXkHLrhREMfiT5KYEtrsA2A-xFCdvqwM2hNTNf7Y6VGe0Z48EDIyO5p5DxdNFsaSChUcb
iRUhSyRXIGWr_ZKkGM9GoyoVWCBk3Ni2Td7zkZ1EfAIeRJobiOnYXKE6Q

```

whereas iam role has full ec2 access, with following policy

```auto
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": "ec2:*",
      "Effect": "Allow",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "elasticloadbalancing:*",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "cloudwatch:*",
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": "autoscaling:*",
      "Resource": "*"
    }
  ]
}

```

Any suggestions please.

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [June 25, 2014, 1:28pm UTC](https://forum.ansible.com/t/aws-ec2-instance-create-via-ansible-iam-roles-instance-profile-name-unauthorizedoperation-error/15542/2 "2014-06-25T13:28:13Z")

</div>

Are you showing the credentials of the role you are using to create  
the EC2 instance or those of the role the new EC2 instance will be?

---

<div class="post-metadata">

**Author:** ![Faisal\_Ali\_Rabbani](https://avatars.discourse-cdn.com/v4/letter/f/278dde/32.png) [@Faisal\_Ali\_Rabbani](https://forum.ansible.com/u/Faisal_Ali_Rabbani)\
**Post date:** [June 26, 2014, 5:21am UTC](https://forum.ansible.com/t/aws-ec2-instance-create-via-ansible-iam-roles-instance-profile-name-unauthorizedoperation-error/15542/3 "2014-06-26T05:21:28Z")

</div>

Obviously I have not shared credentials this is the policy of role, which has full access of ec2.

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [June 26, 2014, 1:10pm UTC](https://forum.ansible.com/t/aws-ec2-instance-create-via-ansible-iam-roles-instance-profile-name-unauthorizedoperation-error/15542/4 "2014-06-26T13:10:24Z")

</div>

Sorry, I wasn't clear. Are you showing the policy rules of the role  
being created or the one doing the creation? It's the permissions of  
the one doing the creation (not the one being attached to the new EC2  
instance) that matters.

---

<div class="post-metadata">

**Author:** ![Faisal\_Ali\_Rabbani](https://avatars.discourse-cdn.com/v4/letter/f/278dde/32.png) [@Faisal\_Ali\_Rabbani](https://forum.ansible.com/u/Faisal_Ali_Rabbani)\
**Post date:** [June 26, 2014, 3:33pm UTC](https://forum.ansible.com/t/aws-ec2-instance-create-via-ansible-iam-roles-instance-profile-name-unauthorizedoperation-error/15542/5 "2014-06-26T15:33:53Z")

</div>

thanks Micheal for response.  
It is t ![](https://ssl.gstatic.com/ui/v1/icons/mail/images/cleardot.gif)he policy doing the creation.

---

<div class="post-metadata">

**Author:** ![Pawel\_Guc](https://avatars.discourse-cdn.com/v4/letter/p/cdc98d/32.png) [@Pawel\_Guc](https://forum.ansible.com/u/Pawel_Guc)\
**Post date:** [December 18, 2015, 5:39pm UTC](https://forum.ansible.com/t/aws-ec2-instance-create-via-ansible-iam-roles-instance-profile-name-unauthorizedoperation-error/15542/6 "2015-12-18T17:39:21Z")

</div>

Hi!

> I am trying to create EC2 instance via ansible using IAM roles but I while launching new instance I get error

Did you figure it out?

---

<div class="post-metadata">

**Author:** ![Baraa\_Basata1](https://avatars.discourse-cdn.com/v4/letter/b/848f3c/32.png) [@Baraa\_Basata1](https://forum.ansible.com/u/Baraa_Basata1)\
**Post date:** [December 20, 2015, 6:24am UTC](https://forum.ansible.com/t/aws-ec2-instance-create-via-ansible-iam-roles-instance-profile-name-unauthorizedoperation-error/15542/7 "2015-12-20T06:24:32Z")

</div>

Faisal,

Just to confirm that the IAM Instance Profile itself is set up correctly, are you able to successfully launch an EC2 instance with this IAM Role outside of Ansible, such as using the AWS Console?

-Baraa
