title: How to temporarily switch profiles for AWS CLI?
body: <p>Updated answer (7/10/2021): For AWS CLI v1, do this:</p>
  <pre class="lang-sh prettyprint-override"><code>export AWS_DEFAULT_PROFILE=user2
  </code></pre>
  <p>For AWS CLI v2, the following will work:</p>
  <pre class="lang-sh prettyprint-override"><code>export AWS_PROFILE=user2
  </code></pre>
  <p>The full question is below for context:</p>
  <hr />
  <p>(1.) After successfully configuring a second profile for the AWS CLI, I unsuccessfully tried to set the profile to user2 in my bash session with the following command:</p>
  <pre><code>export AWS_PROFILE=user2
  </code></pre>
  <p>... per the advice here: <a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html" rel="noreferrer">https://docs.aws.amazon.com/cli/latest/userguide/cli-multiple-profiles.html</a></p>
  <p>(2.) The following command works:</p>
  <pre class="lang-sh prettyprint-override"><code>aws s3 ls --profile user2
  </code></pre>
  <p>So I know that the AWS CLI and the user2 profile are both working on my computer.</p>
  <p>(3.) However, when I subsequently (that is, after entering &quot;export AWS_PROFILE=user2&quot;) try something like:</p>
  <pre class="lang-sh prettyprint-override"><code>aws s3 ls
  </code></pre>
  <p>... AWS's response assumes that I want to query it as the default user (NOT user2)</p>
  <p>(4.) So the only way I can use the user2 profile from the command line is by continuing to append &quot;--profile user2&quot; to every single command, which is tedious.</p>
  <p>(5.)</p>
  <pre class="lang-sh prettyprint-override"><code>echo $AWS_PROFILE
  </code></pre>
  <p>yields:</p>
  <pre class="lang-sh prettyprint-override"><code>&gt;&gt; user2
  </code></pre>
  <p>, as expected.</p>
  <p>Any idea what's going on here? I'm sure I'm making some dumb mistake somewhere.</p>