Amazon ec2 - AWS EC2 instance crashes for user via Ansible

I am trying to instantiate ec2 and faced the following problem:

msg: Instance creation failed => UnauthorizedOperation: 
You are not authorized to perform this operation. 
Encoded authorization failure message: ....very long encoded message.

      

Update: This only happens when using a privacy and access key for a specific user in my account. If I use root access keys, then it works. But that's not what I want to do. I think I missed something about how users log in with ec2.

My ansible yml uses aws access and secret key in that order.

---
- hosts: localhost
  connection: local
  gather_facts: no
  vars_files:
  - test_vars.yml
  tasks:
  - name: Spin up Ubuntu Server 14.04 LTS (PV) instance
    local_action:
      module: ec2
      region: 'us-west-1'
      aws_access_key: "{{ aws_access_key }}"
      aws_secret_key: "{{ aws_secret_key }}"
      instance_type: 't1.micro'
      image: ami-f1fdfeb4
      wait: yes
      count: 1

    register: ec2

      

+3


source to share


2 answers


You need to go to the AWS IAM console ( https://console.aws.amazon.com/iam ) and grant this user (associated with an access key in your script) and grant him permissions (policies) to create EC2 instances.



It looks like your "root" user account on AWS already has these permissions if it helps anyone to compare two users to figure out which policy you need to add - you could just create an EC2 group with the correct policy from the policy generator and add this user to this EC2 group.

+3


source


It looks like an AWS permission issue. The root user has full permission, so it will definitely work with that. Make sure your AWS specific user has permission to launch the instance.



0


source







All Articles