title: AWS CLI giving InvalidClientTokenId error when Ansible is running well
body: <p>I have the following set-up:</p>
  
  <ol>
  <li>A script <code>updatecreds.py</code> runs, which updates AWS credentials in my Ansible creds file using STS.</li>
  <li>Now, I took those creds to run AWS-related tasks in Ansible, and they run smoothly. But, the CLI commands give me an error.</li>
  <li>When I use the same credentials in the <code>~/.aws/config</code> file, I get the following error when executing CLI commands: <code>A client error (InvalidClientTokenId) occurred when calling the ListAccessKeys operation: The security token included in the request is invalid.</code></li>
  </ol>
  
  <p>As some of my Ansible tasks run shell commands which are AWS cli commands, this behaviour is messing with my Ansible run too.</p>
  
  <p>Why is AWS behaving so weirdly?  Or did I do something wrong here?</p>
  
  <p>PS : My <code>~/.aws/config</code> looks like this:</p>
  
  <pre><code>[default]
  aws_access_key_id=&lt;&gt;
  aws_secret_access_key=&lt;&gt;
  aws_session_token=&lt;&gt;
  region=us-east-1
  </code></pre>