Ansible not reading credentials from ~/.aws/credentials
<p>I am running ansible with <code>dynamic inventory</code>. When the <code>aws cli</code> was setup with aws configure command than the ansible commands with dynamic invetory was running properly. But I want to have multiple profiles to be used by dynamic inventory so I have added profile in <code>~/.aws/credentials</code></p>

<pre><code>[personal]
aws_access_key_id = XXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXX

[default]
aws_access_key_id = XXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXX
</code></pre>

<p>ansible not picking up these credentials and on running <code>./ec2.py --list</code> it is giving the error:</p>

<pre><code>Looks like AWS is down again:
EC2ResponseError: 401 Unauthorized
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;Response&gt;&lt;Errors&gt;&lt;Error&gt;&lt;Code&gt;AuthFailure&lt;/Code&gt;&lt;Message&gt;Authorization header or parameters are not formatted correctly.&lt;/Message&gt;&lt;/Error&gt;&lt;/Errors&gt;&lt;RequestID&gt;349d5311-54db-4e79-9bbc-2d60b9f15da5&lt;/RequestID&gt;&lt;/Response&gt;
</code></pre>

<p>After @uptime365's answer, this is most likely not an Ansible/ec2.py problem. Here's my troubleshooting steps:</p>

<h3>Can you use the <code>awscli</code> with those credentials?</h3>

<pre><code>aws ec2 describe-instances --page-size 5
aws ec2 describe-instances --page-size 5 --profile personal
</code></pre>

<h2>Can you use <code>awscli</code> with the credentials manually included?</h2>

<p>Note there's no need to use <code>profile</code> since you are specifying the keys.</p>

<pre><code>AWS_ACCESS_KEY_ID="AKIA.." AWS_SECRET_ACCESS_KEY=".."  aws ec2 describe-instances --page-size 5
</code></pre>

<p>If it complains about the region, add <code>AWS_DEFAULT_REGION="us-east-1"</code> or the region of your choice.</p>

<h2>Neither of these work</h2>

<p>You have a problem with your access key or secret. How many characters are in each? The key should be 20 characters, all uppercase letters and numbers. The secret is 40 characters, upper/lower/numbers/punctuation.</p>

python amazon-web-services ansible aws-cli